Multi filters

Multi filters

ramsettyramsetty Posts: 3Questions: 1Answers: 0

Hello,

I am trying to implement filters in my page from this URL.

https://datatables.net/examples/api/multi_filter_select.html

we have 7 columns in the datatables and we have a requirement to apply the default filter turned on for one of the columns with two pre-selected values.

I am able to pre-select two values in one of the filters, but datatables still shows all rows without filtering. how can we set the filter with default values turned on?

Here is my code. Thanks in advance for your help.

    initComplete: function () {
        this.api().columns().every(function () {
            var column = this;
            var hideFilter = ' style="visibility:hidden" '

            if (column.header().innerText == 'Referral Name' || column.header().innerText == 'Status') {
                hideFilter = ''
            }

            var select = $('<select ' + hideFilter + ' multiple="multiple"><option value="">All</option></select>')
                .appendTo($(column.footer()).empty())
                .on('change', function () {
                    var vals = $('option:selected', this).map(function (index, element) {
                        return $.fn.dataTable.util.escapeRegex($(element).val());
                    }).toArray().join('|');

                    column
                        .search(vals.length > 0 ? '^(' + vals + ')$' : '', true, false)
                        .draw();
                });

            column.data().unique().sort().each(function (d, j) {
                var sel;

                if (d == 'CMA-Draft' || d == 'Audit') {
                    sel = 'selected'
                }

                select.append('<option ' + sel + ' value="' + d + '">' + d + '</option>')
                sel = '';

            });
        });
    }

Thanks
Ram

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.