locked
Why Datatable after filter when click second page the filter will auto remove RRS feed

  • Question

  • User1734598475 posted

    I have facing a issue when i doing custom filtering. In the first page table result is correct when go to second the table will auto remove the filter. Can i know how to fix the issue?

      $.fn.dataTable.ext.search.push(
            function (settings, data, dataIndex) {
                var temp_filter = $('#Form_INB_ServiceRequest_Listing input[name=view_types]:checked').val();
                //alert(temp_filter);
                var data4 = data[4]; // use data for the age column
                if (temp_filter != "") {
                    if (data4 == temp_filter) {
                        return true;
                    }
                } else {
                    return true;
                }
    
                return false;
            }
        );
    
        Table_ServiceRequest_Listing.draw();
        $.fn.dataTable.ext.search.pop();
    Monday, July 16, 2018 5:49 AM

All replies

  • User36583972 posted


    Hi jackson anbiz,

    According to your description and code, I’ve made a sample on my side. But I did not reproduce your issue.  

    I suggest that you could refer to the code of my sample. I assumed the value of the checkbox is 41 and filtered by Age in column 4.

    Here is the JS code.

        <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
        <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
        <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"/>
        <script type="text/javascript">
            $(document).ready(function () {
                var table = $('#example').DataTable();        
                $.fn.dataTable.ext.search.push(
                    function (settings, data, dataIndex) {
                        var temp_filter = $("input[name=cbox]:checked").val();
                        var data4 = data[3]; 
                        if (temp_filter != "") {
                            if (data4 == temp_filter) {
                                return true;
                            }
                        } else {
                            return true;
                        }
                        return false;
                    }
                );
                table.draw();
                $.fn.dataTable.ext.search.pop();
            });
        </script>
    

    The Html code.

    <body>
        <div>
            <input id="Checkbox1" type="checkbox" name="cbox" value="41" checked="checked"/>
        </div>
    <table id="example" class="display" style="width:100%"> 
    <!-- the data -->
        </table>
    </body>
    </html>

    Best Regards,

    Yong Lu

    Tuesday, July 17, 2018 9:12 AM