SearchPanes Options - return rowData[n] equal to 'string' returns nothing

SearchPanes Options - return rowData[n] equal to 'string' returns nothing

glimpsed_chaosglimpsed_chaos Posts: 113Questions: 22Answers: 4

Link to test case: https://live.datatables.net/jaxeqewi/1/edit?html,js,output
Error messages shown: None
Description of problem: Following the SearchPanes Custom Filtering I have setup a test case that works similar to my use.

The first 2 appear in the SearchPane (same as the default example). The next 2 do not appear in the SearchPane.

The only difference here is that I would like to qualify where they are equal to the string value instead of not equal to.

                options: [
                    //THIS WORKS 
                    {
                      label: 'Not Edinburgh',
                      value: function (rowData, rowIdx) {
                        return rowData[2] != 'Edinburgh';
                        }
                    },
                    {
                      label: 'Not London',
                      value: function (rowData, rowIdx) {
                        return rowData[2] != 'London';
                        }
                    },
               //NOT WORKING
                    {
                      label: 'Is Edinburgh',
                      value: function (rowData, rowIdx) {
                        return rowData[2] == 'Edinburgh';
                        }
                    },
                    {
                      label: 'Is London',
                      value: function (rowData, rowIdx) {
                        return rowData[2] == 'London';
                        }
                    },                  
                  
                ],

My end goal here is to have a fixed set of filters that appear even if the count is 0.

It might appear as:
London 13
Edinburgh 12
Chicago 0

If my approach is wrong to achieve that, please let me know. I could not locate another method to implement a fixed set of filter options.

Thank you for your time!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,332Questions: 26Answers: 4,774

    They don't show because you enabled searchPanes.cascadePanes which removes rows with 0 count. Commented it out in htis updated example:
    https://live.datatables.net/jaxeqewi/2/edit

    Kevin

  • glimpsed_chaosglimpsed_chaos Posts: 113Questions: 22Answers: 4

    @kthorngren

    I can see that, however, doing so returns 0 count for all 4 options in that filter. And the "Position" filter is completely empty. My understanding was that cascadePanes set to true meant that it would calculate other filters counters based on current selected filters but I have nothing selected either, so I would expect it to be there.

    The "office" filter should have counts based on the returns and the example page for this.

  • kthorngrenkthorngren Posts: 20,332Questions: 26Answers: 4,774
    edited February 22 Answer ✓

    however, doing so returns 0 count for all 4 options in that filter. And the "Position" filter is completely empty.

    Yep, I didn't look close enough. Since you are using rows.add() after initialization to add the rows you will need to use searchPanes.rebuildPane() to update the options. Updated example:
    https://live.datatables.net/yibomaqa/1/edit

    I added Is Chicago to demonstrate 0 count. See the searchPanes.rebuildPane() after the rows.add().

    However if you load the data at initialization time, ie, HTML table, data or ajax, then searchPanes.rebuildPane() is not needed. Updated example with data.
    https://live.datatables.net/gunahake/1/edit

    My understanding was that cascadePanes set to true meant that it would calculate other filters counters based on current selected filters

    The docs do have this:

    Allow panes to cascade under selection.

    It seems your expectation is correct. @allan can comment on the expected behaior and what changes are needed.

    EDIT: initially forgot to link to the second example.

    Kevin

  • glimpsed_chaosglimpsed_chaos Posts: 113Questions: 22Answers: 4

    @kthorngren That works great! Thank you so much!

  • glimpsed_chaosglimpsed_chaos Posts: 113Questions: 22Answers: 4

    @kthorngren - One more follow up...

    The documentation for rebuildPane indicates that the default is FALSE. Flag to decide whether to maintain the selections in the pane or not.

    I put in a short timer to show this. It will remember what I selected if set to TRUE. Select...wait at least 5 seconds for the interval to pass and see that it remains selected.

    But the "Position" is empty and "Office" have 0 values.

    https://live.datatables.net/yibomaqa/3/edit

    I need to be able to remember the selections, have the options populated with values.

    Thoughts?

  • kthorngrenkthorngren Posts: 20,332Questions: 26Answers: 4,774

    The searchPanes.rebuildPane() docs specify the first parameter, if any are supplied, is to be the index of the pane to rebuild. You need to specify this when passing true. Updated example:
    https://live.datatables.net/yibomaqa/4/edit

    Kevin

  • glimpsed_chaosglimpsed_chaos Posts: 113Questions: 22Answers: 4

    @kthorngren - My apologies... I read through that but was interpreting that as "rebuild all panes (true) or rebuild all panes (false). Or possible (rebuildPanes(1, true)) if you only wanted that pane rebuilt.

    I see now where is says "Optional - No" for index. So, I would need to rebuild and pass the index and true for each searchPane. Such as: rebuildPane(1, true).searchPanes.rebuildPane(2, true);

    Thanks again!

Sign In or Register to comment.