Deka87 Deka87 - 10 months ago 84
Javascript Question

Datatables rowId starting with a number issue

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.
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: "",
  columns: [{
    "data": "uid"
  }, {
    "data": "location"
  }, {
    "data": "date"
  // Set rows IDs
  rowId: function(a) {
    return 'id_' + a.uid;

Fiddle here