Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
How to passing variable id from js to controller then show in datatables based on selected option

I have aplication with condition... when option division selected, then show modal form with datatable based on selected option , i'am using laravel8

My code in view..

                        <div class="form-group row"> <label for="divisi" class="col-sm-2 col-form-label"> Pilih
                            Divisi</label>
                        <select class="col-sm-5 form-control custom-select" name="divisi" id="divisi">
                            <option selected>-- Pilih --</option>
                            @foreach ($divisi as $key => $item)
                                <option value="{{ $key }}">{{ $item }}</option>
                            @endforeach
                        </select>
                    </div>

and My Code in Js

    $('#divisi').change(function() {
        var id_divisi = $('#divisi').val();
        var tableCustomer;
        var tableProduk;
        let _token = $('meta[name="csrf-token"]').attr('content');
        console.log(id_divisi);
        $.ajax({
            type: 'GET',
            url: "{{ route('penjualand.getBarang') }}",
            data: {
                id_divisi: id_divisi
            },
            chache: false,

            success: function(brg) {
                console.log('SUCCESS', brg);
                tableProduk = $('.table-produk').DataTable({
                    responsive: true,
                    processing: true,
                    serverSide: true,
                    retrieve: true,
                    autoWidth: false,
                    ajax: {
                        url: "{{ route('penjualand.getBarang') }}",
                    },
                       columns: [
                     {data: 'DT_RowIndex', searchable: false, sortable: false},
                     {data: 'kode'},
                     {data: 'nama'},
                     {data: 'hargaJual'},
                 ]
                });

My controller

    public function getBarang(Request $request)
{
    $selectedDiv = $request->id_divisi;
    $barang = DB::table('barang')->where('divisi_id',$selectedDiv)->get();

    return datatables()
    ->of($barang)
    // ->addIndexColumn()
    // ->addColumn('kode', function ($barang) {
    //     return ($barang->kode);
    // })
    ->rawColumns([])
    ->make(true);
}

when combo box selected item change, my datatables dont return anything in modal form. Please advice...

thanks in advance

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!