How do I add button on each row in datatable?
Basically your code is okay, thats the right way to do this. Anyhow, there are some misunderstandings:
fetchUserData.cfm does not contain key/value pairs. So it doesn't make sense to address keys in mData. Just use
mData[index]
dataTables expects some more info from your serverside. At least you should tell datatables how many items in total are on your serverside and how many are filtered.
I just hardcoded this info to your data. You should get the right values from counts in your server sided script.{
"iTotalRecords":"6",
"iTotalDisplayRecords":"6",
"aaData": [
[
"1",
"sameek",
"sam",
"sam",
"sameek@test.com",
"1",
""
],...If you have the column names already set in the html part, you don't need to add sTitle.
The mRender Function takes three parameters:
- data = The data for this cell, as defined in mData
- type = The datatype (can be ignored mostly)
- full = The full data array for this row.
So your mRender function should look like this:
"mRender": function(data, type, full) {
return '<a class="btn btn-info btn-sm" href=#/' + full[0] + '>' + 'Edit' + '</a>';
}
Find a working Plunker here
DataTable add a button to each row
You need a database to persist the state of button. Check below link for server-side processing:
https://datatables.net/examples/data_sources/server_side.html
How to add buttons in each row of data table?
you might be able to use the scoped slot in the component try this:
<b-table>
<template v-slot:cell(actions)="data">
<button @click="myAction">Click</button>
</template>
</b-table>
how to add edit/delete buttons in each row of datatable
well for update and delete button , you need an ID, i assumed the id on database will named as id
$(document).ready(function() {
$('#newexample').dataTable({
"bProcessing": true,
"sAjaxSource": "fetchdata.php",
"aoColumns": [
{ mData: 'title' } ,
{ mData: 'name' },
{ mData: 'year_name' },
{
mData: '',
render: (data,type,row) => {
return `<a href='link_to_edit/${row.id}'>update</a>`;
}
}
],
});
});
reference this
Datatable get button on each row
You can use the node function .node()
function to get the element of the selected row. Then you can wrap it in jQuery to perform jQuery actions on it like this:
$('#apply-all').on('click', function (e) {
var table = $('.mydatatable').DataTable();
table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
var data = this.data(); // able to fetch the data.
var row = this.node();
var rowJqueryObject = $(row);
//or
$(row).find('button'); //will return all buttons in that row
} );
});
Adding button to each row of a datatable with event in angular 2
You can do it using defaultContent
key in columns object of datatable. First you need to create a <th>
for showing the button column. I have created a stackblitz for achieving this. Please read the comments i have added in that stackblitz carefully before implementing it in your logic. I have added three buttons in it which show the data of current row. See: Buttons In Datatable
Is there a way to add button on each row in datatable? [react js]
in my project I use for this purpose something like this:
let buttonDetails = "<a href='" + urlDetails + "' title='" + titleDetails +"' class='dtDetails' data-target='#remoteModal1' data-toggle='modal' data-backdrop='static'><span class='glyphicon glyphicon-search'></span></a>";
let buttonEdit = "<a href='"+urlEdit+"' title='"+titleEdit+"' class='dtEdit' data-target='#remoteModal' data-toggle='modal' data-backdrop='static'><span class='glyphicon glyphicon-pencil'></span></a>";
let buttonDelete = "<a href='" + urlDelete + "' title='" + titleDelete +"' class='dtDelete' data-target='#remoteModal1' data-toggle='modal' data-backdrop='static'><span class='glyphicon glyphicon-remove'></span></a>";
...
"columnDefs": [
...
{
"targets": [2],
"width": miCustomWidth,
"className": "center",
"data": function (d) {
return buttonDetails.replace("ID_X", d.rowIdField) + " " + buttonEdit.replace("ID_X", d.rowIdField) + " " + buttonDelete.replace("ID_X", d.rowIdField);
}
}
...
]
Vue - how can i add a button to each row in a Vuetify datatable?
You can add a new column, set value to action
for example, and add a slot
in the table as follows:
new Vue({
el:"#app",
vuetify: new Vuetify(),
data() {
return {
search: '',
headers: [
{ text: 'Asset', value: 'symbol' },
{ text: 'Amount', value: 'amount' },
{ text: 'Send', value: 'action' }
],
balances: [
{ symbol: "$", amount: 100 },
{ symbol: "$", amount: 200 },
],
}
},
methods: {
sendRequest(rowData) {
console.log(rowData)
}
}
});
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script><link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
<v-app id="app">
<v-data-table
:headers="headers"
:items="balances"
:items-per-page="5"
class="elevation-1"
>
<template v-slot:item.action="{ item }">
<v-btn @click="sendRequest(item)">
Send
</v-btn>
</template>
</v-data-table>
</v-app>
Related Topics
Regular Expression to Accept Both Positive and Negative Numbers
Want to Show/Hide Div Based on Dropdown Box Selection
Delete Span Tag Along With Text in HTML Permanently
How to Clear Location.State in React-Router on Page Reload
How to Prevent the Keyboard from Popping Up on Mobile Devices
How to Combine Object Values from Separate Lines into One Line
Ng2-Smart-Table Bind 'Add New' Button Event to an External Button
How to Remove the X-Axis from a Bar Chart Produced by Google'S Visualization API
Discord.Js Sending Message to Specific Channel
Uncaught Typeerror: (Intermediate Value)(...) Is Not a Function
How to Instantiate a File Object in JavaScript
How to Disable Eslint Rule Max Line Length for Paragraph in <Template> of Vue.Js
Why Is the Onclick Event Triggered Twice
What Is the Purpose of the Dollar Sign in JavaScript
Sticky Header Smoothing Scroll Down
Filter Json Object to String Array by Key Value
How to Prevent iOS Keyboard from Pushing the View Off Screen With CSS or Js
In Nest.Js, How to Get a Service Instance Inside a Decorator