How can use a custom code of js-switch in Datatables Function

How can use a custom code of js-switch in Datatables Function

SpiralSpiral Posts: 2Questions: 1Answers: 0

Hi!

I'm using a js-switch for toggle active & in_active status how can use in yajra datatables this is code plz give me the best way so that use in datatables blade script

how can pass js-switch class to controller from datatables to controller plz give me exampel from my code so that understand

    $(document).ready(function(){
    var columns = [
    columns.push({
                    data: 'is_active', 
                    name: 'is_active',
                    orderable: true,
                    searchable: "true",                     
                    className: "js-switch",

                });
         ];
    $('#consultant-table').DataTable({                
                processing: true,
                serverSide: true,                                              
                ajax: {
                    url: '{{ route('admin.product.dt') }}',
                },
                columns: columns
            }); 

            $('.js-switch').change(function () {
                let is_active = $(this).prop('checked') === true ? 1 : 0;
                let id = $(this).data('id');
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '{{ route('admin.product.update_status') }}',
                    data: {'is_active': is_active, 'id': id},
                    success: function (data) {
                        toastr.options.closeButton = true;
                        toastr.options.closeMethod = 'fadeOut';
                        toastr.options.closeDuration = 100;
                        toastr.success(data.message);
                    }
                });
            });
    });

controller

  ->addColumn('is_active', function ($consultant) { 
                $consultantId = $consultant->id;
                $consultantStatus = $consultant->user->is_active;               
                $html = "";
                $html .= "<input type=\"checkbox\" data-id='$consultantId' name=\"is_active\" class=\"js-switch\"            
  $consultantStatus == 1 ? 'checked' : '' >";

                return $html;
            });
This discussion has been closed.