Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82412

Exact dropdown match search

$
0
0

Hi Allan,

I am trying to make an exact match, but it is not working for me. Could you please give me a hand on this?

this is my initComplete code:

initComplete: function (oSettings, json) {
                var col = 0;
                this.api().columns().every(function () {
                    if (col === 2 || col === 7 || col === 8 || col === 10) {
                        var column = this;

                        var select = $('<select class="styled-select"><option value="">All</option></select>')
                            .prependTo($('#tblList').find('thead tr:eq(0) th:eq(' + col + ')'))
                            .on('change', function () {
                                var val = $.fn.dataTable.util.escapeRegex(
                                    $(this).val()

                                );
                                column
                                    //.search(val ? '^' + val + '$' : '', true, false)
                                    .search(this.value)
                                    .draw();
                            });
                        if (col === 2) {
                            json.meta.assetModules.map(function (item) {
                                select.append('<option value="' + item.Name + '">' + item.Name + '</option>')
                            });
                        }
                        if (col === 7) {
                            json.meta.assetTypes.map(function (item) {
                                select.append('<option value="' + item.Name + '">' + item.Name + '</option>')
                            });
                        }
                        if (col === 8) {
                            json.meta.status.map(function (item) {
                                select.append('<option value="' + item.Name + '">' + item.Name + '</option>')
                            });
                        }
                        if (col === 10) {
                            json.meta.wards.map(function (item) {
                                select.append('<option value="' + item.Name + '">' + item.Name + '</option>')
                            });
                        }
                    }
                    col++;
                });
            },

For (col === 8) the possible values on the drop down list are (Active , Not Active) the option "Not Active" is filtered ok but when I choose Active is loading as well the "Not Active", I know the reason is because it contains also the word "Active". I would like to make an exact match on this one. I have tried code like this to replace code between lines 14-17:

if (col === 8) {
    column
        .search(val ? '^' + val + '$' : '', true, false)
        .draw();
}
else {
    column
        //.search(val ? '^' + val + '$' : '', true, false)
        .search(this.value)
        .draw();
}

Also I tried these other ones:

regExSearch = '^\\s' + myValue +'\\s*$';
table.column(columnNo).search(regExSearch, true, false).draw();
table.search( '"My exact match"' );

Thanks,
Wilson


Viewing all articles
Browse latest Browse all 82412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>