laravel-datatables icon indicating copy to clipboard operation
laravel-datatables copied to clipboard

How to pass extra parameter with other default parameter

Open jatinbphp opened this issue 7 years ago • 8 comments

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 ?

jatinbphp avatar Apr 09 '18 13:04 jatinbphp

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.

yajra avatar Apr 17 '18 02:04 yajra

@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); }

Surrendra avatar Oct 28 '18 15:10 Surrendra

Are you using the html builder or writing your own script?

Anyways, try this js:

$('#..').DataTable({
    ajax: {
        url: '',
        data: function(data) { data.key = value; } 
    },
    ...
})

yajra avatar Oct 30 '18 01:10 yajra

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'

yaj

laurence702 avatar Mar 08 '20 21:03 laurence702

@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();
});

yajra avatar Mar 10 '20 00:03 yajra

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 avatar Aug 25 '20 10:08 UmeshKrRana

@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()) }

FerBiani avatar Feb 05 '21 16:02 FerBiani

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();
                }'
            ]));

MilanUnjiya4149 avatar Jul 06 '21 10:07 MilanUnjiya4149

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.

github-actions[bot] avatar Sep 18 '23 00:09 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Sep 25 '23 00:09 github-actions[bot]