How to filter out rows with null values

How to filter out rows with null values

mihalispmihalisp Posts: 76Questions: 15Answers: 0

Hi,

i am trying to use a checkbox to filter a Datatable column
When the checkbox is checked i want the Datatable to show only non null-non empty rows.

I have searched the forum,i found similar posts talking about the opposite (eg. show only nulls ) but didn't find a way to achieve this.

For my other filters i have used:

  $('input:checkbox[name="chk_box"]').on('change', function () {
  //build a regex filter string with an or(|) condition
  var filter = $('input:checkbox[name="chk_box"]:checked').map(function() {
  return this.value; 
  }).get().join('|');

  table.column(17).search(filter ? '^((?!value1|value2).*)$' : '', true, false, false).draw(false);

I have also deen these about filtering null values.how can i revert it to achieve the desired result?

   //table_elleimma_iperwria.column(17).search( '^$', true, false ).draw();
   //table_elleimma_iperwria.column(17).search( '' ).draw();

Thanks.

Answers

  • kthorngrenkthorngren Posts: 6,113Questions: 21Answers: 1,353

    I think I would create a Search Plugin for this. Here is an example:
    http://live.datatables.net/fehobiti/1/edit

    Using the search plugin has the advantage that it will run anytime the table is searched, sort, etc - anytime there is a table draw.

    Kevin

  • mihalispmihalisp Posts: 76Questions: 15Answers: 0

    Thank you Kevin!

    I have also found another working solution for anyone interested!
    Can you check it please?

     $('input:checkbox[name="chk_box"]').on('change', function () {
    
     if ($(this).is(':checked')) { 
                     table
                    .column(17) // or columns???
                    .search( '^(?!\s*$).+', true, false )
                    .draw();
    
        }
        else {
                     table
                    .column(17)
                    .search( '' ) 
                    .draw();
        }
    
Sign In or Register to comment.