Hide column present in JSON DataTable with server side processing

I followed this post: DataTable: Server Handling in ASP.Net
I use this code to initialize a DataTable:

<script type="text/javascript"> $(function () { $('#example').dataTable({ 'bProcessing': true, 'bServerSide': true, 'sAjaxSource': '/data.ashx' }); }); </script> 

My JSON looks something like this:

 { "iTotalRecords": "57", "iTotalDisplayRecords": "57", "aaData": [ [ "id001", "Name001", "Addr001", ], [ "id002", "Name002", "Addr002", ] ] } 

I want to achieve the 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 id <tr> , I use:

 "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull) { $(nRow).attr("id",aData[0]); return nRow; } 

But it does not hide the ID column. Please help.

Update: I found the perfect solution for my problem.
I have to create my JSON below

  { "iTotalRecords": "57", "iTotalDisplayRecords": "57", "aaData": [ [ "0":"Name001", "1":"Addr001", "DT_RowId": "id001", ], [ "0":"Name002", "1":"Addr002", "DT_RowId": "id002", ] ] } 

Check out this link for more information: DateTable - automatically add row id

+4
source share
1 answer

Use aoColumnDefs to hide the column. Datatables example

 $('#datatable').dataTable({ aaData: aaData, "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { //console.log(nRow); $(nRow).attr("id", aData[0]); return nRow; }, "aoColumnDefs": [ { "bSearchable": false, "bVisible": false, "aTargets": [0] }, ] });​ 

Fiddle work

+5
source

Source: https://habr.com/ru/post/1440467/


All Articles