Filter data-tables using two or more dependent(cascading) drop-down list box

Filter data-tables using two or more dependent(cascading) drop-down list box

GaneshAherGaneshAher Posts: 2Questions: 1Answers: 0

I'm trying to apply filters to my data-table with drop-down list box which are dependent. But when i'm trying to select a value from drop-down, data-table takes value from only one drop-down.[https://stackoverflow.com/questions/49504657/how-to-filter-data-tables-using-two-or-more-dependent-drop-down-list] this is the link to my stackoverflow question having detailed description about my requirement.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @GaneshAher,

    In the SO code, it looks like you're doing this:

        $('#areaId').on('change', function(){
          if (this.value == 1) {
            dataTable.search("Midlands & East of England").draw();
          } else {
            dataTable.search("North East, Yorkshire & Humberside").draw();
          }
        });
        $('#cluster_id').on('change', function(){
           dataTable.search(this.value).draw();   
        });
    

    search() only searches on the last search given, removing the previous search. So, as you say, the search is only searching on areaId, or clusterID, it's not combining the two!

    If you want those two ANDed together, that's easy (where A and B are the values!):

    table.search(A + " " + B);

    If you want them ORed, you'll need to use regular expressions in the search:

    table.search('(' + A + '|' + B + ')', true);

    Hope that helps,

    Cheers,

    Colin

  • GaneshAherGaneshAher Posts: 2Questions: 1Answers: 0

    Hi, @colin Thanks for reply.
    I've solve that issue, but now I'm facing new challenge. I'm trying to search using multiple drop-down list box with multiple select value for drop-down. I've posted my updated code in same Stackoverflow Question. If it possible please have look into that and help me. My aim is that when I'm selecting an area and same time I can able to filter by selecting more than one clusters dependent on that area .
    https://stackoverflow.com/questions/49504657/how-to-filter-data-tables-using-two-or-more-dependent-drop-down-list

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @GaneshAher ,

    It looks like there's several answer to that SO question, so I'm guessing this is now resolved? If not, I'd suggest opening a new forum question here with the exact problem in a single place, so that it's clear which code/problem is being looked it.

    Cheers,

    Colin

This discussion has been closed.