I am using this code to init DataTable:
$('#table-groups').dataTable( {
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bFilter": false,
"bInfo": false,
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"aoColumns": [
{ "sClass": "name" },
{ "sClass": "tools", "bSortable": false},
],
});
Now I am adding rows via server-side script like this:
$('#table-groups').dataTable().fnAddData( ["<strong>"+$_returnvalue.name+"</strong>","<div class=\"cell edit\"> Group ID is: "+$_returnvalue.entryid+" </div>"]);
And my question: is there a way to insert value of $_returnvalue.entryid
to be ID of the <tr>
?
To add a row, define a variable that keeps the count of the total number of that now exists in the table. Then we will use the jQuery “click” event to detect a click on the add row button and then use the .append () method of jQuery to add a row in the table. Each row element has been assigned an id Ri that we will later use to delete a row.
In order to tackle the second problem, we will get all the rows next to the row where the remove button is clicked using the .nextAll () method of jQuery and then iterate across each of these elements to modify the row index and row id. The code is as follows: This code can be modified in several ways according to the needs.
You are not using serverside datatable here. This answer may help those who are using serverside datatable and trying to put unique ID (from serverside, based on db data). You just have to send the ID by this key: DT_RowId (from serverside, as response).
Legacy interface notice: This discussion was created before the release of DataTables 1.10, which introduced a more modern API. The documentation for the old DataTables API is still available and newer versions are backwards compatible, but the primary documentation on this site refers to DataTables 1.10 and newer.
You are not using serverside datatable here. This answer may help those who are using serverside datatable and trying to put unique ID (from serverside, based on db data).
You just have to send the ID
by this key: DT_RowId
(from serverside, as response). It doesn't require any change in the frontend. More details of this can be found in the following link: https://datatables.net/examples/server_side/ids.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With