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

Multiple Check boxes to update table

$
0
0

Hi,

I am new datatable and need some help.
I have a table that loads correctly, but I want to put two check boxes that both will act on the same column.
When check box 1 is tick it hides some rows based on column x (say column 4), when check box 2 is checked is display some rows based on a another value in the same column (column 4).

The way i would like to operate is both check boxes will act on the same column say column 4:
if check box 1 is ticked, then check box 1needs be unchecked and the data as per check box 1 criteria is displayed.
if check box 2 is ticked, then check box 1needs be unchecked and the data as per check box 2 criteria is displayed.

Now I have this half working , second method (check box 2) is working but I cant't seem to get the check box 1 to behave the same way.
Below is the code I am using.

    $(document).ready( function () {
               .
.
.
.
.
                $.fn.dataTable.ext.search.push(
                function (settings, searchData, index, rowData, counter) {

                    var checkedcmp = $('input:checkbox[name="chk_boxcmp"]').is(':checked');
                    var checked = $('input:checkbox[name="chk_box"]').is(':checked');


                    if (checked && searchData[4] != '') {
                        document.getElementById("chk_boxcmp").checked = false;
                        //document.getElementById("chk_boxcmp").disabled = true;
                        return false;
                    } 

                    if (checkedcmp && searchData[4] == '' ) {
                        document.getElementById("chk_box").checked = false;
                        //document.getElementById("chk_box").disabled = true;
                        return false;
                    } 

                    // Otherwise display the row
                    return true;

                });                   

                var table = $('#stocktbl').DataTable();

                $('input:checkbox').on('change', function () {

                    // Run the search plugin
                    table.draw();

                }

            );



        } );

Any help will be appreciated.
Thanks
George


Viewing all articles
Browse latest Browse all 82603

Latest Images

Trending Articles



Latest Images

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