when i hit print,pdf,excel,csv buttons it returns only json instead of print page or excel
when i hit print,pdf,excel,csv buttons it returns only json instead of print page or excel
my problem : everything is working but when i hit print,pdf,excel,csv buttons it returns only json, and i do not want that,i want to
get pdf or excel or print page.
i provided a very simple example on using yajra-laravel-datatable
and here are
View = (table + js script)
controller = only 2 methods (index , index_ajax)
*here is the table
app_num | app_type | secrecy | urgency | importancy |
---|---|---|---|---|
here is the js code
$(document).ready(function () {
const table = $('#inbox_tbl').DataTable({
processing: true,
serverSide: true,
ajax: {
url: "{!! route('inbox_ajax') !!}",
type: 'GET'
},
columns: [
{data: "id"},
{data: "apptypes.type_name"},
{data:"app_master_details.secrecies.name"},
{data:"app_master_details.urgencies.name"},
{
"data": null,
render: function (data, type, row) {
return data.app_master_details.importancies.name;
}
}
],
@if(app()->getLocale()==='ar')
"language": {"url": "../public/ar.json"},
@endif
buttons: [
{
extend: 'copy',
text: 'Copy current page',
exportOptions: {
modifier: {
page: 'current'
}
}
},
{extend: 'pdf'},
{extend: 'colvis'},
{
extend: 'print',
exportOptions: {
page: 'current'
}
},
{extend: 'excel'}
],
search: {
"smart": true,
"regex": true
},
select: {
select: true,
style: 'multi',
},
dom: "Bfltip",
initComplete: function () {
$arr = ['{{trans("lang.appid")}}', '{{trans("lang.apptype")}}', '{{trans("lang.secrecylevel")}}'
, '{{trans("lang.urgencylevel")}}', '{{trans("lang.importancylevel")}}'
];
var counter = 0;
this.api().columns().every(function () {
var column = this;
var input = document.createElement("input");
input.placeholder = $arr[counter];
counter++;
$(input).appendTo($(column.footer()).empty())
.on('change', function () {
column.search($(this).val(), false, false, true).draw();
});
});
}
});
table.on('preXhr.dt', function (e, settings, data) {
data.search_value = $('input[type="search"]').val();
})
/*$('input[type="search"]').on('change',function () {
table.DataTable().ajax.reload();
return false;
});*/
});
here is the controller
public function inbox(AppInboxDataTable $dataTable)
{
return $dataTable->render('layouts.applications.inbox');
// return view('layouts.applications.inbox', ['data' => $data]);
}
public function inbox_ajax(AppInboxDataTable $dataTable)
{
$data = AppMaster::whereHas('applifecycles', function ($query) {
$query
->where('rec_user_id', Auth::id())
->where('seen', '<>', 1)
->where('state_id', 2)
->orWhere([
['rec_user_id', ''],
['rec_dept_id', auth()->user()->employees->dept_id]
]);
})
->where('app_state_id', '<', 3)
->with(
'apptypes',
'applifecycles',
'app_master_details',
'app_master_details.urgencies',
'app_master_details.importancies',
'app_master_details.secrecies'
)
->get();
if (request()->ajax()) {
return \datatables()->collection($data)->make(true);
}
return $dataTable->render('layouts.applications.inbox', ['data' => $data]);
}
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin