Author Topic: Supply nested objects keys to colModel dataIndx  (Read 2015 times)

EPM Solutions

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 182
    • View Profile
Supply nested objects keys to colModel dataIndx
« on: December 25, 2017, 03:43:18 pm »
Hello,

I have and nested object and want to show result of child object key in dataIndx for example below

  var obj_demo = [{
        "Name": "Name1",
        "Department": "Department1",
        "ID": "ID1",
        "Place": {
          "Place1": "Place1",
          "Place2": "Place2",
          "Place3": "Place3"
        }
      },
      {
        "Name": "Name2",
        "Department": "Department2",
        "ID": "ID2",
        "Place": {
          "Place1": "Place1",
          "Place2": "Place2",
          "Place3": "Place3"
        }
      },
      {
        "Name": "Name3",
        "Department": "Department3",
        "ID": "ID3",
        "Place": {
          "Place1": "Place1",
          "Place2": "Place2",
          "Place3": "Place3"
        }
      }
    ];

I am able to print values of Name, Department, ID. I want to print values of Place object's key using dataIndx: "Place1", dataIndx: "Place2", dataIndx: "Place3", as below for example.

var col_m = [{
        title: "Name",
        dataType: 'string',
        dataIndx: 'Name'
      },
      {
        title: "Department",
        dataType: 'string',
        dataIndx: 'Department'
      },
      {
        title: "Place1",
        dataType: 'string',
        dataIndx: 'Place1',
      },
      {
        title: "Place2",
        dataType: 'string',
        dataIndx: 'Place2',
      },
      {
        title: "Place3",
        dataType: 'string',
        dataIndx: 'Place3',
      }
    ]

I could see we can achieve this by rendering place field as below only if we have one object. Multiple object does not work as we can not give dateIndx:"Place" mulitple times as it should be unique.

      title: "Place1",
        dataType: 'string',
        dataIndx: 'Place',
        render: function(ui) {
          if (ui.rowData.Place == undefined) {
            return ""
          } else {
            return ui.rowData.Place.Place1;
          }
        }

Is there any way to achieve above result?
I implemented for one object and found this working (only to show values) but when i apply grouping on Place, it does not work and shows below error

jquery.min.js:5 Uncaught TypeError: this.replace is not a function
    at Object.String.trim (ScriptResource.axd?d=6VBhEWNoJ2VmJYkC4E.....4:5)
    at b.extend.trim (jquery.min.js:3)
    at pqgrid.min.js:16
    at pqgrid.min.js:16
    at Array.forEach (<anonymous>)
    at pqgrid.min.js:16
    at h (pqgrid.min.js:16)
    at pqgrid.min.js:16
    at Array.forEach (<anonymous>)
    at h (pqgrid.min.js:16)

here is my groupmodel;

var groupModel = {
      on: true,
      dataIndx: ['Place'],
      summaryInTitleRow: 'all',
      titleInFirstCol: true,
      fixCols: false,
      indent: 20,
      collapsed: [false, false, false],
      title: [
        "{0} ({1})",
        "{0} - {1}"
      ]

    };



paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Supply nested objects keys to colModel dataIndx
« Reply #1 on: December 25, 2017, 05:28:08 pm »
Nested objects are not supported.

you would need to convert it into plain object format while loading data in the grid.