Author Topic: Serialize detailmodel as json object with data  (Read 6023 times)

dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Serialize detailmodel as json object with data
« on: September 23, 2015, 05:47:40 am »
What is the right way to serialize main grid so that its' detailed model serialized as an object with properties defined via detailmodel dataIndx for each column?

With the following code child grid is not accessible as an object:

var rawData=$( "#grid_array" ).pqGrid( "option" , "dataModel.data" );           
   var str = { "dataArray": rawData };
   var str1 = JSON.stringify(str);   


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Serialize detailmodel as json object with data
« Reply #1 on: September 24, 2015, 04:09:52 pm »
detailModel is a callback function and functions can't be serialized with JSON.stringify.

What's your requirement, there may be an alternative way to do that.

dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: Serialize detailmodel as json object with data
« Reply #2 on: September 29, 2015, 11:51:43 pm »
I'd like to get a data array for each row with it's detail model (so basically I need to get data from "sub-rows" in an array form). I was looking through demo-s but couldn't find an example how to do it.

dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: Serialize detailmodel as json object with data
« Reply #3 on: October 02, 2015, 06:00:10 am »
Hi Param,

So is there a way to do it? Retrieving data from nested grids sounds like something that should be supported in the product, I'd assume?

Thank you.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Serialize detailmodel as json object with data
« Reply #4 on: October 06, 2015, 12:07:53 am »
The detail row can be accessed for every row as rowData property i.e., rowData.pq_detail

To check whether row is expanded or closed: rowData.pq_detail.show = true/ false.

To get reference to the grid in detail row.

var $child_grid = rowData.pq_detail.child.find( ".pq-grid" );

Hope it helps.

dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: Serialize detailmodel as json object with data
« Reply #5 on: October 06, 2015, 12:09:59 am »
Thank you.

Is there a way to retrieve data for all the rows in one shot though? So that I get all rows with all their subrows in one array.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Serialize detailmodel as json object with data
« Reply #6 on: October 06, 2015, 12:40:27 am »
All the data is available through dataModel.data which is just an array of rowData, so you would need to iterate over them and further lookup their properties.

Code: [Select]
var data = grid.option( 'dataModel.data' );
for ( var i = 0; i < data.length; i ++ ){
  var rowData = data[ i ];
}


dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: Serialize detailmodel as json object with data
« Reply #7 on: October 06, 2015, 04:40:04 am »
I tried your suggestion and I get an error
"rowData.pq_detail is undefined" (I checked that the rows do have detail data)

Here's my code

var data=$( "#grid_array" ).pqGrid( "option" , "dataModel.data" );           


for ( var i = 0; i < data.length; i ++ )
{
     var rowData = data;
     if (rowData.pq_detail) // is never true, although data does exist
     {
     var $child_grid = rowData.pq_detail.child.find( ".pq-grid" );
     rowData["PackageContent"] = $child_grid.pqGrid( "option" , "dataModel.data" );
     }
   }

dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: Serialize detailmodel as json object with data
« Reply #8 on: October 07, 2015, 03:46:30 am »
correction: rowData = data [ i ] ; (looks like autocorrection eliminated indexing)