According to the Datatables specs, I can add a unique ID to every row in my table:
$('#myTable').DataTable( {
ajax: '/api/staff',
rowId: 'staffId'
} );
However, the same spec says that IDs cannot start with a number. staffId
in my case is a number, I tried to add some prefix to it:
$('#myTable').DataTable( {
ajax: '/api/staff',
rowId: 'id_' + 'staffId'
} );
However, this didn't work. Any ideas?
Use function-expression
as a value for rowId
and return manipulated string to be used as ID
var appListTable = $(".app-list__table").DataTable({
dom: "",
// Load json with list of applicants
ajax: "https://api.myjson.com/bins/391gc",
columns: [{
"data": "uid"
}, {
"data": "location"
}, {
"data": "date"
}],
// Set rows IDs
rowId: function(a) {
return 'id_' + a.uid;
},
});
Fiddle here
This is a simple solution, just use
rowId: [1]
This will set the value of first column as row id
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