I followed this post: DataTable: Server Side Processing in ASP.Net
I am using this code to initialize DataTable:
<script type="text/javascript">
$(function () {
$('#example').dataTable({
'bProcessing': true,
'bServerSide': true,
'sAjaxSource': '/data.ashx'
});
});
</script>
My JSON is something like this:
{
"iTotalRecords": "57",
"iTotalDisplayRecords": "57",
"aaData": [
[
"id001",
"Name001",
"Addr001",
],
[
"id002",
"Name002",
"Addr002",
]
]
}
I want to achieve same as below:
<table id="datatable">
<thead>...</thead>
<tbody>
<tr id="id001">
<td>Name001</td>
<td>Addr001</td>
</tr>
<tr id="id002">
<td>Name002</td>
<td>Addr002</td>
</tr>
.
.
</tbody>
</table>
NOTE:
To assign the id to <tr>
I am using:
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$(nRow).attr("id",aData[0]);
return nRow;
}
But it is not hiding the ID
column.
Please help.
Update:
I found a perfect solution for my problem.
I must create my JSON as below
{
"iTotalRecords": "57",
"iTotalDisplayRecords": "57",
"aaData": [
[
"0":"Name001",
"1":"Addr001",
"DT_RowId": "id001",
],
[
"0":"Name002",
"1":"Addr002",
"DT_RowId": "id002",
]
]
}
For more information check this link: DateTable - automatic row ID addition