How to select all entries for any matching filters (OR logic across panes)

How to select all entries for any matching filters (OR logic across panes)

zbmcscnfzbmcscnf Posts: 6Questions: 1Answers: 0

Live test case: http://live.datatables.net/tifugeto/1/edit?html,output

I'm trying to build an interface that allows users to select ALL records that match ANY selected filters. In the live example a user should be able to select L1, L2, or L3 from each category and have those selections treated as an "OR" rather than an "AND". For instance, if a user selects Cat A L3 and Cat B L3 I still want it to show 2 entries, not 0 entries. Is this possible using SearchPanes? I suspect it's not... If not, is there a better way to go about this?

I tried SearchBuilder, but I don't want to present such a complicated set of search options to the user. I want to confine their options to selecting one level from each category (like I'm doing with SearchPanes), but I don't see a way to do something similar with SearchBuilder.

Can anyone point me in the right direction? Has anyone modified SearchPanes to allow something like this? Otherwise, is it possible to create an interface with SearchBuilder that looks similar to what I have with SearchPanes? Thanks for your time.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923

    I haven't used SearchPanes much but believe you are correct that it doesn't support OR searches. You can create a search plugin for this. This thread links to an example. There are other threads/examples showing OR searches.

    Kevin

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

    That's right. We do have an open ticket for this already (DD-1075 for my reference) and we'll report back here when there's an update.

    Colin

  • zbmcscnfzbmcscnf Posts: 6Questions: 1Answers: 0

    Thanks for the reply Kevin.

    Colin, the ticket is to add OR support across panes?

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

    Yep, OR support. It won't be fixed in the immediate future, as we're focused on other areas right now, but hopefully before too long.

    Colin

  • zbmcscnfzbmcscnf Posts: 6Questions: 1Answers: 0

    Understood, thank you!

  • zbmcscnfzbmcscnf Posts: 6Questions: 1Answers: 0

    Updated test case: live.datatables.net/tifugeto/4/edit?html,output

    @kthorngren I took your advice to look into creating a search plugin. The plugin I have so far works when I statically code the columns, but I'd like to use the 3 dropdown menus to choose the columns. I have the values assigned to the choices, but I don't know how to update the search plugin with those choices when selected.

    I'm thinking it needs to look something like this, but I can't get this to update when choices are made in the dropdown menu.

    $.fn.dataTable.ext.search.push(function( settings, searchData, index, rowData, counter ) {
        if (searchData[cat_a_col] === 'X') {
            return true;
        }
        if (searchData[cat_b_col] === 'X') {
            return true;
        }
        if (searchData[cat_c_col] === 'X') {
            return true;
        }
        return false;
    });
    

    I'm completely new to Javascript so I'm sure it's something obvious...but I've been trying to figure this out for a while and I'm not getting anywhere. Any help would be appreciated!

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    You need to call draw() when the input values change to trigger a re-search.

    Allan

  • zbmcscnfzbmcscnf Posts: 6Questions: 1Answers: 0

    Thanks for your reply. I did try adding .draw(); in several places, but I haven't been able to update the table with the dropdown choices. Where should that call go?

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923
    Answer ✓

    Create a change event handler for your drop down lists. In the event handler call the draw() API. This example is a checkbox example but its calling draw() to run the search plugin:
    http://live.datatables.net/wenaxuti/1/edit

    Kevin

  • zbmcscnfzbmcscnf Posts: 6Questions: 1Answers: 0
    edited January 2021

    Thanks @allan and @kthorngren ! There were a couple other things wrong with my Javascript that were messing things up as well, but your two replies helped me piece this together. Final working version: live.datatables.net/tifugeto/8/edit

This discussion has been closed.