Search on specific columns doesn't work why?

Search on specific columns doesn't work why?

rhayve92rhayve92 Posts: 5Questions: 1Answers: 0

Hi,

I have problem with searching for specific columns. Whenever the user inputs in the column search field it is also inputting on the general 'Search' field.

below is my code:

getFormalQuotes(obj) {

        if (this.props.formalquote_list.length > 0) {
            if ($.fn.DataTable.isDataTable('#formalquote-table')) {
                this.props.formalquote_list.empty();
                this.props.formalquote_table.DataTable().clear().destroy();
            }
        }

        this.props.formalquote_table.DataTable({
            ajax: {
                url: obj.url,
                type: obj.type,
                beforeSend: (xhr) => {
                    xhr.setRequestHeader('Authorization', 'Bearer ' + obj.token);
                    xhr.setRequestHeader('Accept', obj.dataType);
                },
                dataSrc: ""
            },
            columns: [
                {data: 'quote_type'},
                {data: 'insurer_name'},
                {data: 'section_name'},
                {data: 'policy_wording'},
                {data: 'created_at'},
                {data: 'updated_at'},
                {data: 'id'},

            ],
            columnDefs: [
                {
                    targets: [6],
                    data: 'id',
                    render: (data, type, row, meta) => {
                        return "<a class='btn btn-sm btn-primary btn-download-formalquote fa fa-download text-white' data-id='" + data + "' role='button' download></a>"
                            + "<a class='btn btn-sm btn-warning btn-edit-formalquote fa fa-pencil' data-id='" + data + "' role='button'></a>" +
                            "<a class='btn btn-sm btn-danger btn-delete-formalquote fa fa-trash text-white' data-id='" + data + "' role='button'></a>";
                    }
                }
            ],

            initComplete: (settings, json) => {
                let api = settings.oInstance.api();
            
                   api.columns().every((colIdx) => {
                        $('.formal-filter', api.column(colIdx).footer()).on('keyup change clear', (evt) => {
                            if (api.search() !== $(evt.target).val()) {
                                api
                                    .search($(evt.target).val())
                                    .draw();
                            }
                        });
                    });

            }

        });
    }

This question has an accepted answers - jump to answer

Answers

Sign In or Register to comment.