Autocomplate filter:
It's used to filter data by one value, and this value is searched in the same data or other.
| ID | Username | Firstname | Lastname |
|---|
$dt->addfilter(filed_name,'autocomplete',label,operator);
operator takes the following values: =
<
>
>=
<=
!=
like
How to create it?
static function respond_filters_autocomplete_filed_name($search){
//can be fetched from database
return parent::respond_filters_tag([1=>'Ahmad',2=>'Ali']);
}
respond_filters_tag requires a two-dimensional array (key,value)
/* in the action of your controller put the following code:*/
$dt = new Your/Datatable/Class(
array(
'firstname' => 'Firstname',
'lastname' => 'Lastname'
));
$dt->addfilter('username','autocomplete','Username','like');
return $dt->display('Your/Blade/Template',$request);
in your datatable put the following code:
static function respond_filters_autocomplete_username($search){
$records=\DB::table('mdl_user')->where('username', 'like', '%'.$search.'%')->get();
$d=[];
foreach ($records as $record){
$d[$record->username]='User: '.$record->username;
}
return parent::respond_filters_tag($d);
}
in your blade template where you want your datatable appears put the following code:
@include('phpdt::datatable_view')
@section('datatable_section')
@parent
@show
By: Mohammad Alaa Aldeen
Git: https://github.com/mhdalaaaldeen