Filter/Exclude the word "Never" from Table

Filter/Exclude the word "Never" from Table

muttBunchmuttBunch Posts: 4Questions: 1Answers: 0

I can do the following and it filters out everything except for rows containing "Never"...

oTable.columns(6).search('Never').draw();

As amazing as DataTables is, why can't it be as simple as doing:

.search(!'Never')

Basically, I have a table that is displaying from an Admin panel, a list of users and their last logins to the site. I want to filter on the word "Never" so it only shows users that have an actual login date. The Last Logon column is column 6.

Checking with Google, it brought me to one example using a regEx which I don't see why I would need that to exclude a word from the search, then again, maybe I'm misunderstanding regular expressions. If someone could provide me an example, I would greatly appreciate it.

Thanks,

muttBunch

This question has accepted answers - jump to:

Answers

  • muttBunchmuttBunch Posts: 4Questions: 1Answers: 0

    Forgot to mention that I have this tied to a checkbox

    $('#filter_neverLoggedIn_checkbox').on('click', function () {
                    $(this).val(this.checked ? true : false);
                    console.log($(this).val());
                    if ($(this).val() === "true") {
                        $('#filter_neverLoggedIn').val('true');
    
                        oTable.columns(6).search('Never').draw();
    
                    } else {
                        if ($(this).val() === "false") {
                            $('#filter_neverLoggedIn').val('false');
                        }
                    }
    
                });
    
  • colincolin Posts: 12,897Questions: 0Answers: 2,199
    Answer ✓

    When you say 'exclude' rows that have 'Never', do you mean remove those rows entirely from the table. If so, this example from this thread should help - it's talking about removing duplicate rows but the same principles would apply,

    Colin

  • kthorngrenkthorngren Posts: 14,101Questions: 25Answers: 3,325
    Answer ✓

    Use a regex expression and enable regex and disable smart search for the column().search() call. See the search() docs and this example for more info.

    Kevin

  • muttBunchmuttBunch Posts: 4Questions: 1Answers: 0

    Thank you, will give both suggestions a try and mark answers. Thanks again

  • muttBunchmuttBunch Posts: 4Questions: 1Answers: 0

    I was able to do it with the following regex, thanks again for your help

    oTable.columns(6)
       .search('^((?!Never).)*$', true, false)
       .draw();
    
Sign In or Register to comment.