How to generate jQuery DataTables rowId client side? -
the jquery datatables reference shows example of setting rowid
option column data source (server side). setting used "select" extension , retaining row selection on ajax reload.
is there way generate row identifier value 1) client side, or 2) combination of multiple columns data source?
example data source:
{ "data": [ { "aid": 5421, "bid": 4502, "name": "john smith" } }
code:
$("#datatable").datatable({ select: true, //rowid: "aid" each row id value of "aid" column // e.g., <tr id="5421"> //rowid: 0 each row id value of 0-indexed column // e.g., <tr id="5421"> (same above) rowid: [0, 1] // how? row id combined value of 2+ columns // e.g. <tr id="5421-4502"> rowid: "random" // how? random generated client-side id // e.g., <tr id="id34e04"> });
apparently there's no way directly. workaround, use ajax.datasrc
option and/or rowid
option:
// example using datasrc option manipulate data: $("#example").datatable({ ajax: { url: "data.json", datasrc: function (json) { (var = 0, ien = json.data.length; < ien; i++) { json.data[i][0] = '<a href="' + json.data[i][0] + '">view message</a>'; } } } });
Comments
Post a Comment