Author Topic: use format, deFormat with filtering  (Read 4149 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
use format, deFormat with filtering
« 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) + "%";
}
« Last Edit: April 24, 2019, 08:02:17 am by paramquery »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Format
« Reply #1 on: April 20, 2019, 09:03:00 am »
Code: [Select]
format: function(val) {
return pq.formatNumber(val * 100, "# ###") + "%";
}

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Format
« Reply #2 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?
« Last Edit: April 23, 2019, 03:33:56 pm by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: use format, deFormat with filtering
« Reply #3 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

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: use format, deFormat with filtering
« Reply #4 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?
« Last Edit: April 24, 2019, 02:54:00 pm by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: use format, deFormat with filtering
« Reply #5 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, "# ###") + "%");
},
« Last Edit: April 24, 2019, 08:57:21 pm by paramquery »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: use format, deFormat with filtering
« Reply #6 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?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: use format, deFormat with filtering
« Reply #7 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.