connect select2 with datatables for multiselect dropwdown
connect select2 with datatables for multiselect dropwdown

I tried to view the select2 function into a datatable. But it does not work.
My blade is:
<select id="dataGender" class="form-control select2-allow-clear" style="width:200px;" name="namaDUN" >
<option value="">Select</option>
@foreach ( $dataName as $item)
<option value="{{$item->Jantina}}">{{$item->Jantina}}</option>
@endforeach
</select>
Controller:
public function gender(Request $request)
{
$dataGender = [];
if($request->has('q')){
$search = $request->q;
$dataGender = DB::table("modified_dpprs")
->select("id","Jantina")
->where('Jantina','LIKE',"%$search%")
->get();
}
return response()->json($dataGender);
}
script:
$('.dataGender').select2({
placeholder: 'Select..',
ajax: {
url: '/select2-autocomplete-ajax_gender',
dataType: 'json',
delay: 250,
processResults: function ($dataGender) {
return {
results: $.map($dataGender, function (item) {
return {
text: item.Jantina,
id: item.id,
}
})
};
},
cache: true
}
});
This discussion has been closed.
Answers
How are you trying to use select2 with Datatables? Is this with Editor?
What exactly isn't working?
Do you get errors in your browser's console?
In order to help debug we will need to see the problem. please post a link to your page or a test case replicating the issue.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin