Add/Remove a search criteria among others

Add/Remove a search criteria among others

trucmuche2005trucmuche2005 Posts: 71Questions: 22Answers: 2

Hello,

I'm using textfields to perform filtering among columns like in this example. I added on the top of the table a checkbox which, when checked, should only display lines where the column named "ms" is not empty. I do a simple table.column("ms:name").search("^\s*$", true).draw(); when the checkbox is checked and a table.column("ms:name").search("").draw(); when unchecked.

BUT now, I remark that :
1) i check the checkbox and the correct lines are shown in the table
2) I write something in the textbox of a column to filter the displayed results ; It works...
3) I remove what I wrote in this textbox and I see that ALL lines appears, even those who don't match "^\s*$" criteria : the checkbox is now forgotten !

And now I understand that the search criteria first written in the column textfields are also forgotten when, after, I check the checkbox since checking this checkbox does not ADD a search criteria but DEFINES (and overwrites) existing search criteria.

How can I do to ensure that the criteria set by the checkbox is always filtering the table until the checkbox is unchecked ??

Is there a way to ADD/REMOVE search criteria to those who already exists ?

Thanks for your help !

t.

This question has an accepted answers - jump to answer

Answers

  • trucmuche2005trucmuche2005 Posts: 71Questions: 22Answers: 2

    Hello ?

    Let me explain this problem more simply, maybe...

    on the top of a table like this where I can multi-filter using input fields, I have to put checkboxes to display only rows where third column is equal to "10", "20", or "30". But this additional filter should co-exist correctly with the input fields...

    How can I achieve this ?

    Many thanks in advance...

    T.

  • trucmuche2005trucmuche2005 Posts: 71Questions: 22Answers: 2

    Hello,
    I did not managed to find a solution yet. Could you please help me to add a checkbox on the top of a datatable which would add a condition (3rd column = "10") to existing filtering when checked and remove this additional condition (3rd column = "10") when unchecked ?
    Many thanks in advance,
    T.

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770
    Answer ✓

    Have you tried creating a search plugin to filter the column based on the checkboxes?
    https://datatables.net/manual/plug-ins/search#Plug-in-structure

    Can you post a link to your code for review and help?

    Kevin

  • trucmuche2005trucmuche2005 Posts: 71Questions: 22Answers: 2

    Yes, I managed to do something that works with that ! Thanks for your help !!!

This discussion has been closed.