I want to add csv and excel export button to one dataTable only. MyController file:
public function index(Request $request)
{
$Databaseurl = Route('orders.index');
if ($request->ajax()) {
$orders = Order::all();
return datatables()->of($orders)
->editColumn('price', function ($order) {
return '<div class="text-nowrap text-center">'.number_format($order->price, 0, '.', ',').'</div>';
})
->editColumn('address', function ($order) {
return \Illuminate\Support\Str::limit($order->address,25);
})
->editColumn('city', function ($order) {
return '<div class="text-center">'.\Illuminate\Support\Str::limit($order->city,25).'</div>';
})
->addIndexColumn()
->addColumn('action', function($order){
return '<a href="'.route('order.edit',['id' => $order->id]).'" class="text-nowrap btn-sm btn-primary text-center"><i class="far fa-eye"></i> view</a>';
})
->rawColumns(['action','city','price'])
->toJson();
}
return view('order.index',compact('Databaseurl'));
}
and the data table jquery codes:
<script type="text/javascript">
$(function () {
var table = $('.mydatatable').DataTable({
"oLanguage": {
"sUrl": "https://cdn.datatables.net/plug-ins/1.10.19/i18n/Persian.json",
},
"pageLength": 25,
processing: true,
serverSide: true,
ajax: "{{ $Databaseurl }}",
columns: [
{data: 'id', name: 'id'},
{data: 'customer_name', name: 'customer_name'},
{data: 'address', name: 'address', searchable: false},
{data: 'city', name: 'city'},
{data: 'price', name: 'price', searchable: false},
{data: 'created_at', name: 'created_at', searchable: false},
{data: 'action', name: 'action', orderable:false,searchable: false},
],
});
});
</script>
Also I watched this video, but I prefer not to go through more difficult steps and solve this problem in the same controller and blade file. Because I only want this for one view table Is there a solution?