Author Topic: Accessing parent rowData from detailGrid render function  (Read 1861 times)

MEngelbyPQ

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 21
    • View Profile
Accessing parent rowData from detailGrid render function
« on: September 24, 2018, 11:30:00 pm »
It took me a while to figure this out and this is the solution I came up with.  Using code from this thread, I added to the init function for detailGrid:
Code: [Select]
detailModel: {
    init: function (ui) {
        var rowData = ui.rowData,
            model = binDetailModel( $(this).pqGrid('instance'), rowData ),
            $grid = $("<div class='hourDetail' />").pqGrid(model);

        //save reference to rowData in detail grid.
        $grid.data( 'rowData' , rowData);

        return $grid;
    }
}
But I was finding difficulty getting the instance of the detailGrid in the render function.  This is what I settled on:
Code: [Select]
var detailRender = function(ui) {
    var cellContents = {}, cellStyle = '';
    var cellData = parseFloat(ui.cellData);
    // Get the div for this detailGrid
    var $grid = $(this.element).closest( 'div' );
    var rowData = $grid.data('rowData');

    // Logic to change the class based on values in the rowData

    return cellContents;
}

Is this code robust enough to always return the proper detailGrid in $grid or will it return the next following grid when the render function is executed during the last rows of the detailGrid?
Or is there a better way to get the detailGrid from the render callback function when invoked in colModel render?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Accessing parent rowData from detailGrid render function
« Reply #1 on: September 25, 2018, 10:47:08 am »
This example shows how to pass reference of parent grid and row data of parent grid to detail grid.

https://paramquery.com/pro/demos/nesting

MEngelbyPQ

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Accessing parent rowData from detailGrid render function
« Reply #2 on: September 25, 2018, 08:15:05 pm »
I like that method better.  Why I didn't think of it when defining the detailModel is a bit confusing to me now.  But it makes more sense being there.  Thank you for the insight.