laravel-datatables
laravel-datatables copied to clipboard
How to pass extra parameter with other default parameter
Summary of problem or feature request
Hello,
I want to pass one extra parameter with other default parameter which are passing it self on ajax request. I want to pass variable which is not part of data/field which are displaying on tables. Basically i want to add one filter which is not part of currently displaying columns.How i can pass it ?
On minified ajax, you can append an array of parameters that will be included by default on request. Maybe this is what you need? See docs https://yajrabox.com/docs/laravel-datatables/master/html-builder-minified-ajax for ref.
@jatinbphp do you mean like this ?
public function userSkpDataTable($pes)
{
$skp = skp::isAktif($pes,1);
return Datatables::of($skp)
->addColumn('action', function($user)use($pes) {
return ' link with 2 paramter';
})->make(true);
}
Are you using the html builder or writing your own script?
Anyways, try this js:
$('#..').DataTable({
ajax: {
url: '',
data: function(data) { data.key = value; }
},
...
})
Hello Yajra, im trying to pass extra parameter from controller to view when using Yajra, so I get something like total amount made from the time range filter. see screenshot below of my controller. In my view I cant do this {{cashMade}}
I get Errr: Use of undefined constant cashMade - assumed 'cashMade'
@laurence702 you can use with api to append data on response.
Route::get('user-data', function() {
$model = App\User::query();
return DataTables::eloquent($model)
->with('posts', 100)
->with('comments', 20)
->toJson();
});
I have passed the extra parameter with the datatable like this-
->with([
"cities" => app(\App\Http\Controllers\HelperController::class)->cityListing(),
"leadCounters" => $this->leadCounters
])
->make(true);
But, how can I get these extra parameters in the response of Yajra Datatable?
@UmeshKrRana do as follows:
Save the initialization of the DataTable in a variable:
var table = $('.vehicles-report-table').DataTable({...})
Then access the data via the drawCallback function:
drawCallback: function(settings) { console.log(table.ajax.json()) }
Are you using the html builder or writing your own script?
Anyways, try this js:
$('#..').DataTable({ ajax: { url: '', data: function(data) { data.key = value; } }, ... })
return $this->builder()
->setTableId('table')
->columns($this->getColumns())
->minifiedAjax()
->ajax([
'data' => 'function(d) {
d.range = $("#range").val();
d.period_from = $("#period_from").val();
d.period_to = $("#period_to").val();
}'
]));
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been inactive for 7 days since being marked as stale.