Quantcast
Viewing all articles
Browse latest Browse all 82048

filtering table with a checkbox.

There is a checkbox on my page that is supposed to filter the table so that it displays only rows with one error or more. I had implemented this function before and it worked fine. It stopped working all of a sudden when I changed the way that ajax was being called in my code (this was necessary as it was preventing ajax.reload() from working). This is my code which was working before:

    $('input[name=checkB]').change(function () {
                    if ($("#checkB").is(":checked")) {
                        $.fn.dataTable.ext.search.push(
                            function (settings, data, dataIndex) {
                                var num = Number(data[4]);
                                if (num > 0) {
                                    return true;
                                }
                                return false;
                            }
                        );
                    }
                    else {
                        $.fn.dataTable.ext.search.pop();
                        tTable.draw();
                    }
                });

I have since tried the following code instead with no luck:

document.addEventListener("DOMContentLoaded", function (event) {
                var selector = document.querySelector('input[name=checkB]');
                selector.addEventListener('change', function (event) {
                    if (selector.checked) {
                        $.fn.dataTable.ext.search.push(
                            function (settings, data, dataIndex) {
                                var num = Number(data[4]);
                                if (num > 0) {
                                    return true;
                                }
                                return false;
                            }
                        );
                    } else {
                        $.fn.dataTable.ext.search.pop();
                        tTable.draw();
                    }
                });
            });

Anyone have any idea why this has stopped working or how to fix this?
Many thanks


Viewing all articles
Browse latest Browse all 82048

Trending Articles



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