Exclude fields from default search in datatables server side processing

Exclude fields from default search in datatables server side processing

felixweifelixwei Posts: 2Questions: 1Answers: 0
edited November 2019 in Free community support

Hi everyone,
I used ajax server side processing for my datatables. Here is my code.

js code

$('#dt-custom').DataTable({
        ajax: $('#dt-custom').data('action'),
        columnDefs: [
            { targets: 'hidden', searchable: false, visible: false, className: 'noVis' },
            { targets: 'no-orderable', searchable: false, orderable: false },
        ],
        dom: "<'row'<'col-md-3'l><'col-md-5'f><<'col-mr-6 align-middle'B>>tip",
        drawCallback: function() {
            $('.dataTables_paginate > .pagination').addClass('pagination-rounded');
        },
        orderCellsTop: true,
        //scrollX: true,
        select: { style: 'multi+shift' },
        serverSide: true,
        stateSave: true,
    });

laravel blade code

           <table id="dt-custom" class="table table-striped dt-responsive w-100 nowrap" data-action="{{ route('brands.index') }}">
                     <thead>
                            <tr>
                                <th>Name</th>
                                <th>Description</th>
                                <th>Created At</th>
                                <th class="no-orderable">Created By</th>
                                <th class="hidden">id</th>
                            </tr>
                        </thead>
                    </table>

laravel controller code

public function index()
    {
        // go to the model and get a group of records
        if (request()->ajax()) {
            $suppliers = DB::table('suppliers')
                ->whereNull('deleted_at')
                ->select(['name', 'description', 'created_at', 'created_by', 'id']);

            return datatables()->of($suppliers)
                ->rawColumns([5])
                ->make(false);
        }

        // return the view, and pass in the group of records to loop through
        return view('suppliers.index');
    }

I tried to set class "hidden" for field 'id'. Class 'hidden' applied 'searchable: false', but in default search, I can still search value in field 'id'. I suspected this was because I used ajax server side processing.

How can I prevent 'default search' search value from field 'id'? Please help me. Thank you....

Answers

This discussion has been closed.