Is there the posibility to search multiple words within one columns

Is there the posibility to search multiple words within one columns

OliwanOliwan Posts: 5Questions: 1Answers: 0

Howdy to all of you!

I'm working just for some days with datatalbes and of course, I'm very happy with it! Congrats to all of you!

Perhaps any of you can assist me with this:

I want to provide filter checkboxes to akticate/deactivate contents of a column - to minimize / maximize showint content

-> i.e. color of shirts (red,blue,green,orange,black,white)
-> if the user is deactiavting red, than the list should only show no "red" but any other color
-> if the usser is deactiavating red and orange, the list should only show not "red" and not "orange" but any other color

is there a way to handle this?
thanks a lot in advance
Oliwan

Answers

  • OliwanOliwan Posts: 5Questions: 1Answers: 0

    ...what i can do at the moment is only search for one color

    table
    .columns( 2 )
    .search( "red" )
    .draw();

    but I coulnd't figure out how can do this

    table
    .columns( 2 )
    .search( "red","black","white" )
    .draw();

  • OliwanOliwan Posts: 5Questions: 1Answers: 0

    ...also this "regex-seach" isn't clear enought for me

    $('#table_id').DataTable().columns( 2 ).search( "black|white|green", true,false ).draw();

    doesn't work?!

  • kthorngrenkthorngren Posts: 21,339Questions: 26Answers: 4,954

    Your code snippet works here:
    http://live.datatables.net/foladewa/1/edit

    Click the button to see the search filter work. Please provide a link to your page or a test case showing an example of your data and what you are trying to do so we can help debug. You can update my test case.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • OliwanOliwan Posts: 5Questions: 1Answers: 0

    thx a lot!
    I've got it
    Oliver

  • OliwanOliwan Posts: 5Questions: 1Answers: 0
    edited June 2021

    sample code:

    var color="";
    if(document.getElementById('red').checked){color="red|";}
    if(document.getElementById('orange').checked){color+="orange|";}
    if(document.getElementById('green').checked){color+="green|";}
    if(document.getElementById('yellow').checked){color+="yellow|";}
    color=color.substring(0, color.length - 1);

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

    table.columns( 2 ).search( color, true,false ).draw();

Sign In or Register to comment.