ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: mshapiro on August 12, 2015, 05:13:49 am

Title: issue with select filter when options have multiple spaces (2.4.1)
Post by: mshapiro on August 12, 2015, 05:13:49 am
I have string columns in some grids where select filters are populated from the column values.  As in:
{
    title: "Gr Name", dataType: "string", dataIndx: "GrName", width: 200,
    filter: {
   type: 'select', condition: 'equal', valueIndx: "GrName", labelIndx: "GrName",
   prepend: { '': '--Select--' }, listeners: ['change']
    }
}

then after json load:

var column = $gridPeerGroups.pqGrid("getColumn", { dataIndx: "GrName" });
var filter = column.filter; filter.cache = null;
filter.options = $gridPeerGroups.pqGrid("getData", { dataIndx: ["GrName"] });

This works fine unless a column value has sequences of 2 or more spaces.  When that happens, then selecting that entry in the filter drop down will not result in a match.  My workaround is to replace multiple spaces in the filter options with hard spaces as in

for (var i = 0; i < filter.options.length; i++) {
   filter.options.GrName = replaceAll('  ', '&nbsp;&nbsp;', filter.options.GrName);
}

function replaceAll(find, replace, str) {
   return str.replace(new RegExp(find, 'g'), replace);
}
 
Then there is a match when that option is selected in the filter and the correct row(s) are displayed.  Is this the expected behavior?  Is there a better way to do this?  Thanks
Title: Re: issue with select filter when options have multiple spaces (2.4.1)
Post by: paramvir on August 12, 2015, 06:45:45 pm
That is expected behavior.

For condition = "begin"

"Yvonne" would match "Yvonne   Moncada"

"Yvonne " would also match "Yvonne   Moncada"

but "Yvonne M" won't match "Yvonne   Moncada" because there is one space in the former and 3 spaces in the latter.
Title: Re: issue with select filter when options have multiple spaces (2.4.1)
Post by: mshapiro on August 13, 2015, 08:59:23 pm
To be clear, the expected behavior is that if the select condition is 'equal' and one of the column values is "This has 3   spaces"  then an entry of

"This has 3   spaces"

in the filter options will not result in a match when it is selected, but an entry of

"This has 3&nbsp;&nbsp;&nbsp;spaces" 

will result in a match?  Thanks.
Title: Re: issue with select filter when options have multiple spaces (2.4.1)
Post by: paramvir on August 14, 2015, 12:11:55 am
Ok got it, the select list is removing any extra spaces beyond one in the options, which should not be the case, it's being investigated further.

As an alternative workaround, please use the condition as below callback instead of 'equal'.

            condition: function(a, b){
               if( a.replace( /\s/g, '' ) == b.replace( /\s/g, '' ) ){
                  return true;
               }
            },