Author Topic: MultiSelect filter  (Read 7038 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
MultiSelect filter
« on: June 14, 2017, 07:16:25 pm »
I have a column where the data is structured like:

cell1: value1, value2, value3
cell2: value1, value2
cell3: value1


I would like to have a multiselect filter for this column based on the values that are comma separated, ex: value1 applied on above data will return 3 matches, value3 will return 1 match etc

Would this be possible?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: MultiSelect filter
« Reply #1 on: June 14, 2017, 08:59:05 pm »
filter.condition = 'contain'  could be used for this.

https://paramquery.com/pro/api#option-column-filter

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: MultiSelect filter
« Reply #2 on: June 15, 2017, 02:00:47 pm »
Im using that currently (textbox), but I would like to have a multiselect dropdown where its populated with each individual value...
I use multiselect on other columns (one value in each cell) but can't figure it out how to solve it when you have several values in one cell.
« Last Edit: June 15, 2017, 02:22:01 pm by queensgambit9 »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: MultiSelect filter
« Reply #3 on: June 15, 2017, 07:42:10 pm »
Trying:

Code: [Select]
{title:"Test", width:100, align: "left", dataIndx: "Test", hidden: false, filter: { type: 'select',
                         condition: 'contain',
                         options: [ {"test": "test"}],
                         listeners: ['change'],
                               init: function () {
                            $(this).pqSelect({ checkbox: true, width: '100%', multiplePlaceholder: 'TEST', maxDisplay: 0 });
                        },                       
                         }}

But the filter is not applied correctly...

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: MultiSelect filter
« Reply #4 on: June 16, 2017, 01:27:16 pm »
It's more of a javascript related question than a grid related one.

options in filter drop downs are usually filled with getData method, for example the options for ShipRegion are filled in load event in this example: https://paramquery.com/pro/demos/filter_header_local

In your case getData would fill the options from cell values as:

value1, value2, value3
value1, value2
value1

But you want them as

value1
value2
value3.

So you need to write custom javascript to iterate through all rows in dataModel.data and fill cell values in array, then get unique comma separated values.

Code: [Select]
  var arr=[], obj={};
  //get cell values.
  grid.option("dataModel.data").forEach(function(rd) {
arr.push(rd.rank);
  })
 
  //get unique values.
  arr.join(",").split(",").forEach(function(val){
  obj[val]=true;
  })
  arr = Object.keys(obj);
 
  //fill in filter options.
  var filter = grid.getColumn({dataIndx:'rank'}).filter;
  filter.options = arr;
  filter.cache = null;
  grid.refreshHeader();

http://jsfiddle.net/bv2kffqk/

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: MultiSelect filter
« Reply #5 on: June 16, 2017, 02:21:05 pm »
Thanks, seems to work with one value.
When you selected multiple values no match is returned...?


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: MultiSelect filter
« Reply #6 on: June 16, 2017, 04:03:46 pm »
You need to write a custom filter condition for that.

Code: [Select]
condition: function(val, filterBy){
  //write your custom condition here.
},

Example of custom filter: https://paramquery.com/pro/demos/filter_custom
« Last Edit: June 16, 2017, 04:06:16 pm by paramquery »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: MultiSelect filter
« Reply #7 on: June 20, 2017, 06:06:43 pm »
Thanks, works fine.
I have empty values but cannot filter on them currently...what would be the best approach to get empty values filterable?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: MultiSelect filter
« Reply #8 on: June 20, 2017, 10:52:49 pm »
Filtering on empty values is discussed in this post:

https://paramquery.com/forum/index.php?topic=2110.0

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: MultiSelect filter
« Reply #9 on: January 22, 2018, 07:00:08 pm »
In v5.1.0 there seem to be possible to filter on empty values if you use prepend: { '': ''},?
Problem is then filter heading says 1 of 5 but there is only 4 to choose from.
You still need custom condition? How is implemented when using range?

Code: [Select]
{title:"test", width:10, dataIndx: "abc", hidden: true,

        filter: {
        type: 'select',
        attr: "multiple",
        condition: 'range',
        valueIndx: "abc",
        labelIndx: "abc",
        value: [],
        style:'height:30px;',
        prepend: { '': ''},
         listeners: ['change'],

        init: function(ui) {
            ui.$editor.pqSelect({ checkbox: true, width: '100%', multiplePlaceholder: 'FILTER', maxDisplay: 0 });
            }
        }                 
            },

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: MultiSelect filter
« Reply #10 on: January 24, 2018, 11:25:13 am »
Empty values in range condition is supported since old versions.

https://paramquery.com/pro/demos24/filter_header_local ( column shipping Region )

Range condition looks for exact match of multiple values but data in your case is in non standard format, hence the need for custom filter condition.

Please share a plnkr of what you have implemented so far and I would add in it how to look for empty values.

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: MultiSelect filter
« Reply #11 on: January 25, 2018, 08:04:04 pm »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: MultiSelect filter
« Reply #12 on: January 26, 2018, 05:55:25 pm »
There are few issues in your plnkr.

1. Range condition works with strings ( dataType: 'string' ) only.

2. rank is dataType:"integer"; rank: "" is invalid value for an integer. It can be an integer or null or undefined.

Isn't that you had mentioned values like below at beginning of your thread.

cell1: value1, value2, value3
cell2: value1, value2
cell3: value1

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: MultiSelect filter
« Reply #13 on: January 26, 2018, 06:18:01 pm »
Sorry, should be corrected now. I want to have the possibility to filter empty values in rank.
« Last Edit: January 26, 2018, 06:31:31 pm by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: MultiSelect filter
« Reply #14 on: January 29, 2018, 12:28:16 pm »
Empty doesn't work with numbers currently, we are enhancing filtering and it would be supported (range empty, etc for numbers) in the upcoming versions.

If rank is a string column, then empty can be used as in this example https://plnkr.co/edit/ClsPusyvXYJkBAMHCKgn?p=preview