connect select2 with datatables for multiselect dropwdown

connect select2 with datatables for multiselect dropwdown

wnswns Posts: 12Questions: 8Answers: 0
edited November 2019 in Free community support

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

Answers

This discussion has been closed.