datatables editcolumn if else code example
Example 1: datatables editcolumn if else
$data = $this->SourceData->getData();
return Datatables::of($data)
->addIndexColumn()
->editColumn('show', function ($data) {
return ($data->show == 'y')?"Yes":($data->show == 'n')?"No":"";
})
->addColumn('Actions', function($data) {...})
->rawColumns(['Actions'])
->make(true);
Example 2: datatables editcolumn if else
"createdRow": function (row, data) {
$('td', row).eq('COLUMN_INDEX_HERE').html($('<label>').attr({
class: (data.status == 0) ? 'label label-warning' : ( (data.status == 1) ? 'label label-success': 'label label-danger' )
}).html((data.status == 0) ? 'Pending' : ( (data.status == 1) ? 'Approved': 'Canceled' )));
}