jeudi 18 avril 2019

How to pass two parameters in datatable's closure [Serverside]

I need to run a function to check for validity, therefore, I need to pass two variables on closure function. If possible I need to know if i can use global variable inside Datatables.

Example I want to achieve:

return Datatables::of($patients)
        ->addColumn('title', function ($patients,$value) {  
               -- *other codes here*
        })->make(true);

Example 2 if above solution cannot be achieved.

$value="something";    
return Datatables::of($patients)
        ->addColumn('title', function ($patients) {  
               -- use $value here
        })->make(true);

Now I need both $patients and $value to check inside addColumn. If i use the fucntion as above it throws an error [the above code doesnot work with two parameters]. If I try to use a $value from outside then datatable returns undefined variable $value.

I need solution which could either work as below:

  • Either allow me to pass variable through function
  • or Can use global variable inside addColumn

This is a server side Laravel datatables using yajra datatbles package.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire