Hello,
I'm busy learning Laravel.
How can I add an id to a row in a datatable in laravel 5.3?
The id should be the business_type_id from the table.
I looked at [yajra package][1] and installed the demo app but can't understand anything from there, so I'm not using it.
My controller function:
public function businessTypeData(){
$result['data'] = DB::table('business_types')
->selectRaw("business_type_id,
business_type_name,
business_type_slug,
DATE_FORMAT(created_at, '%d/%m/%Y') as created_at")
->get();
return json_encode($result);
}
My js call:
$('#businessTypeTable').DataTable({
select: false,
"ajax": {
"url": "/api/businessType",
"type": "POST",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }
},
"columns": [
{ "data": "business_type_id" },
{ "data": 'business_type_slug', 'visible': false },
{ "data": "business_type_name" },
{ "data": "created_at" },
{"defaultContent": "null", "render": function(data,type,row,meta) {
return '<a href="/businessTypes/'+row.business_type_id+'/edit">'+ '<button class="btn btn-default btn-sm">Edit</button>' + '</a>'+
'<a href="businessTypes/'+row.business_type_id+'/destroy" class="btn btn-danger btn-sm deleteBtn" style="margin-left:10px">Delete</a>';
}
}
]
});
I want my table to look like this:
<table>
<tr id="1">...
<tr id="2">...
[https://github.com/yajra/laravel-datatables-demo] (yajra package)
Can someone please help?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community