Checkboxes "exclusive" filtering

Checkboxes "exclusive" filtering

daveosdaveos Posts: 19Questions: 4Answers: 0

Hi,

http://live.datatables.net/catoponi/1/edit

When I select both the checkboxes A and B, I want the table to only show me the row with "A, B", without the row "B".

How can I achieve that?
Thanks!

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,949Questions: 87Answers: 416
    edited June 2020

    You can build something using this:
    https://datatables.net/manual/plug-ins/search#Example

    This will give you the flexibility you need. I use this a lot for client side filtering. You don't need to develop a plugin but you can just use $.fn.dataTable.ext.search.push in your code.

    Here is an example from my own coding. If you have several data tables on your page you need to make sure you are applying it to the right table. Hence the checks for "undefined". By default it will run on all data tables on your page. It has to run before data table initialization.

    $.fn.dataTable.ext.search.push(
        function( settings, data, dataIndex, row, counter ) {
            //we only do this for the second table
            if ( (typeof row.rfp !== 'undefined') &&
                 (typeof row.rfp_has_creditorview !== 'undefined') )   {
                if (row.rfp_has_creditorview.deleted != null) {                    
                    var ok;
                    ok = filterShowNMonths(row.rfp.update_time);
                    if (ok) {
                        return filterDeleted(row.rfp_has_creditorview.deleted);
                    } else {
                        return false;
                    }
                }
            }
            return true;
        }                
    );
    
  • daveosdaveos Posts: 19Questions: 4Answers: 0

    Thank you for you answer!
    I know it's too much to ask, but is there any way you could show me how it works on a live.datatables.net? I can't seem to make it work by myself...

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    Answer ✓

    Here is a simple example:
    http://live.datatables.net/fojabeqa/1/edit

    You may need to do some basic error checking and data normalization (remove whitespace characters) for more robust solution.

    Kevin

This discussion has been closed.