ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: dbadmin 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);
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
var data = grid.option( 'dataModel.data' );
for ( var i = 0; i < data.length; i ++ ){
var rowData = data[ i ];
}
-
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" );
}
}
-
correction: rowData = data [ i ] ; (looks like autocorrection eliminated indexing)