Custom button with id of the row index (not the row id
Custom button with id of the row index (not the row id
Hi all!
I am new to datatables and having an issue (a 8 hour issue) trying to figure out how to create a custom button that has an id of the current row index from which it was clicked.
Here is my render code:
{
"data": null,
"sortable": false,
"render": function (data, type, row) {
return "<button type='button' class='btn btn-grid-edit btn-xs' data-toggle='modal' id='" + row.id + "' data-id=" + row.id + " data-target='#modal-edit'> Edit </button>";
}
},
The issue is that my row.id skips. I need the actual index of the row. In the "Showing n of n entries" I only have 339 rows...but because my data skips from say 324 to 352 I am getting "undefined" when it tries to return the row.
Thank you for any help!!!
This question has an accepted answers - jump to answer
Answers
Hi Jason,
This example is based on one in the website's examples pages.
It shows the row ID of the clicked on row. Note that the row ID isn't the visible index (i.e. the position of the row in the table), it's the order of the row in the loaded data. This is the index that DataTables uses.
Hope that helps,
Cheers,
Colin
Thank you Colin for the response. I ended up having to just place all the data in the button render:
Its ugly but I couldn't get it to work otherwise. I couldn't use row.id because it was pulling my column "ID" for the row, which could be any number really. And it wouldn't line up with the actual data's row. I feel I have a huge misunderstanding about how to make this work (I spent 9+ hours trying to populate a separate function, trying to pass the data itself, trying to extract the row clicked where the button resided, etc.)...but you did help me! Thank you.