ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: queensgambit9 on April 20, 2019, 02:14:16 am

Title: use format, deFormat with filtering
Post by: queensgambit9 on April 20, 2019, 02:14:16 am
Ok, but how do you set the value as percentage and with thousand separator (# ###)?

Tried:

Code: [Select]
format: function(val) {
return (val * 100) + "%";
}
Title: Re: Format
Post by: paramvir on April 20, 2019, 09:03:00 am
Code: [Select]
format: function(val) {
return pq.formatNumber(val * 100, "# ###") + "%";
}
Title: Re: Format
Post by: queensgambit9 on April 23, 2019, 02:49:44 pm
Having issue with deFormat, how do I apply deFormat on the formatted value to make filtering work?
Title: Re: use format, deFormat with filtering
Post by: paramvir on April 24, 2019, 09:20:48 am
Code: [Select]
//use deFormat as counterpart of format callback
deFormat: function (val) {                   
        return (pq.deFormatNumber(val.split("%")[0], "# ###") / 100);
}


Ex: Freight column in https://paramquery.com/pro/demos/filter_header_local

Please make appropriate changes if you have null/undefined values in the column
Title: Re: use format, deFormat with filtering
Post by: queensgambit9 on April 24, 2019, 02:39:30 pm
Thanks.

Using:

Code: [Select]
{ title: 'test', width: 130, dataIndx: 'test', dataType: 'float', hidden: false, filter: { crules: [{condition: 'between' }] },
  format: function(val) { return pq.formatNumber(val * 100, '# ###') + '%'; },
  deFormat: function (val) { return (pq.deFormatNumber(val.split('%')[0], '# ###') / 100); }
},

On loading the grid I get '0%' inserted in both filter fields.
I have no empty fields in column, and no errors reported.

Filter works fine when using it...but when sorting the column % sign is once again inserted.
See that its the same behaviour in your example...is that by design?
Title: Re: use format, deFormat with filtering
Post by: paramvir on April 24, 2019, 08:52:16 pm
Filter fields for between condition can be kept empty instead of "0%" by updating format callback for empty values.

Code: [Select]
format: function (val) {
       return (val==null || val==="")? "": (pq.formatNumber(val * 100, "# ###") + "%");
},
Title: Re: use format, deFormat with filtering
Post by: queensgambit9 on April 26, 2019, 09:39:48 pm
When sorting '%' sign is still inserted if filter is being applied....would that be possible to remove aswell?
Title: Re: use format, deFormat with filtering
Post by: paramvir on April 27, 2019, 06:30:19 am
'%' is part of the format as per your requirements, it's displayed in both filter fields and column.