Author Topic: How to Filter on Nested Json  (Read 2916 times)

joelclark

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 10
    • View Profile
How to Filter on Nested Json
« on: August 21, 2020, 01:25:01 am »
Hi There,

So I have a few columns that are nested Json. For example the below column. I want to filter on "['FxCalcConfigType']['Value']" but can't get the filter to point to that value. Is this even possibly? I have been looking and have found nothing. Tried the value functionality in the filter and it did not help :(

{
                title: FI.res.fXRates.CalcConfigTypeLabel, dataType: "integer", editable: false, align: "left", minWidth: 150,
                render: function (ui) {
                    //Below line returns the value of the type value so that I don't have to do anything to the entity
                    return ui.rowData['FxCalcConfigType']['Value'];
                },
                filter: { crules: [{ condition: 'contain' }], listeners: ['keyup'] }
            },

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6125
    • View Profile
Re: How to Filter on Nested Json
« Reply #1 on: August 21, 2020, 10:10:27 am »
1. you need to define dataIndx: 'FxCalcConfigType' for your column.

2. write a custom compare function for the column.filter

Code: [Select]
conditions: {
    contain: {
        compare: function (cellData, val) {           
            //write the custom logic here.
        }
    }
}

Here is an example for writing custom filter compare function: https://paramquery.com/pro/demos/filter_custom

Please let me know if you need further assistance on this.
« Last Edit: August 21, 2020, 10:12:14 am by paramvir »

joelclark

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: How to Filter on Nested Json
« Reply #2 on: August 21, 2020, 10:40:52 pm »
Still doesn't seem to be working unless i am missing something? I can't event get into the compare function to debug it. My code is below and as you can see in the attached screenshot it still is showing the data as [Object] [object]

{
                title: FI.res.fXRates.CalcConfigTypeLabel, dataType: "string", dataIndx: "FxCalcConfigType", editable: false, align: "left", minWidth: 150,
                render: function (ui) {
                    //Below line returns the value of the type value so that I don't have to do anything to the entity
                    return ui.rowData['FxCalcConfigType']['Value'];
                },
                filter: { crules: [{ condition: 'contain' }], listeners: ['keyup'] },
                conditions: {
                    contain: {
                        compare: function (cellData, val) {
                            if ((cellData.Value + "").indexOf(val) != -1) {
                                return true;
                            }
                            else {
                                return false;
                            }
                        }
                    }
                }
            },


« Last Edit: August 21, 2020, 10:52:49 pm by joelclark »

tarunsharma

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: How to Filter on Nested Json
« Reply #3 on: May 17, 2022, 01:31:40 am »
Hi, have you able to fix this issue? I am also getting the same issue, cellData return "[Object Object]" and I am not able to read that.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6125
    • View Profile
Re: How to Filter on Nested Json
« Reply #4 on: May 20, 2022, 01:58:33 pm »
Recent version of pqgrid makes it very easy to work with nested json data.

Please check this example: https://paramquery.com/pro/demos/json_nested