I can't create custom attributes with Collection data. Example: <td data-order="data"></td>
. Create custom attributes for row works fine, but I need create attributes for a cell (<td>
). It's possible? This is my code...
return Datatables::of($users)
->addColumn('action', function ($user) {
return '<a href="#edit-'.$user->id.'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
})
->editColumn('id', '{{$id}}')
->removeColumn('password')
->setRowId('id')
->setRowClass(function ($user) {
return $user->id % 2 == 0 ? 'alert-success' : 'alert-warning';
})
->setRowData([
'id' => 'test',
])
->setRowAttr([
'color' => function($user){
return $user->color;
}
])
->make(true);
Adding attribute on td cannot be done on server-side. But it can be done on client-side via js script using createdRow
callback. See example snippet below. Source: http://datatables.net/forums/discussion/31139/how-to-add-data-attribute-in-a-cell-server-side
$('#data-table').DataTable({
ajax: 'some_url',
createdRow: function( row, data, dataIndex ) {
$( row ).find('td:eq(2)').attr('data-validate', '1');
}
});
Thanks!! That's code works fine ;)
@yajra is this serverside supported now ?
Most helpful comment
Adding attribute on td cannot be done on server-side. But it can be done on client-side via js script using
createdRow
callback. See example snippet below. Source: http://datatables.net/forums/discussion/31139/how-to-add-data-attribute-in-a-cell-server-side