user2388554
user2388554

Reputation:

insert custom fields on jquery datatables

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

Upvotes: 2

Views: 3491

Answers (2)

Bret
Bret

Reputation: 401

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>");
   }
 } );

Upvotes: 4

Xavi
Xavi

Reputation: 306

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

Upvotes: 0

Related Questions