2

my datatables fetch from server side for filling table.

i want to insert custom field such as checkbox and buttons on that, like this screen shot: Datatables

thanks

2 Answers 2

4

My suggestion would be to use fnCreatedRow callback. When using this call back it is only called when the row is rendered, and does not effect the data in the table that is associated with datatables.net. When using server side data, make sure the array used has a value (even a blank string "" will work) for the column. Otherwise you will get a datatables error saying it cannot find data for the column it is trying to render.

var oTable = $('#example').dataTable( {
   "fnCreatedRow": function( nRow, aData, iDataIndex ) {
     // nRow - this is the HTML element of the row
     // aData - array of the data in the columns. Get column 4 data: aData[3]
     // iDataIndex - row index in the table
     // Append to the first column
     $('td:eq(0)', nRow).html("<input type='check' value=''></input>");
     // Append the input to the 4th column
     $('td:eq(3)', nRow).html("<input type='button' value='Edit'></input>");
     // Append to 5th column
     $('td:eq(4)', nRow).html("<input type='button' value='Delete'></input>");
   }
 } );
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried to send html code from your server to Datatables in the aaData array (Instead just the value ? )

Example: Instead sending the string "hello world" send something like

"<input type='button' value='Hello world'></input>"

Thats working for me

5 Comments

in returnd json from server? or handly inserting on table?
Json from server, im using php also, you cant edit the Array you send to datatables on php just before sending it ?
i cant edit returnd json array and append that, i'm using PHP
My system use php to get the information from a postgresql database, edits it( formating etc..) and then encodes it to json and send it
no , after edit array or edit that datatables could not return json array correctly and parse on table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.