EasyUI Forum
September 14, 2025, 11:54:12 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Get parent subgrid foreignId in to child subgrid  (Read 8346 times)
rangaNadha
Jr. Member
**
Posts: 50


View Profile
« on: September 29, 2015, 05:52:28 AM »

Hi,

Need to load the subgrid data based on the parent subgrid id column and the parent subgrid foreginId column.
In the below example i need to load the products based on price and order id.

Code:

 var conf = {
            options:{
                fitColumns:true,
                columns:[[
                    {field:'company',title:'Company Name',width:200},
                    {field:'contact',title:'Contact Name',width:200},
                    {field:'country',title:'Country',width:200}
                ]],
                data:[
                    {company:'Speed Info',contact:'Minna John',country:'Sweden'}
                ]
            },
            subgrid:{
                options:{
                    fitColumns:true,
                    foreignField:'companyid',
                    columns:[[
                        {field:'orderdate',title:'Order Date',width:200},
                        {field:'shippeddate',title:'Shipped Date',width:200},
                        {field:'freight',title:'Freight',width:200}
                    ]],
                    data:[
                        {orderdate:'08/23/2012',shippeddate:'12/25/2012',freight:9734}
                    ]
                },
                subgrid:{
                    options:{
                        fitColumns:true,
                        foreignField:'orderid',
                        columns:[[
                            {field:'price',title:'Unit Price',width:200,align:'right'},
                            {field:'quantity',title:'Quantity',width:200,align:'right'},
                            {field:'discount',title:'Discount',width:200,align:'right',formatter:function(value){
                                return value*100+'%'
                            }}
                        ]],
                        data:[
                            {price:923,quantity:2312,discount:0.2}
                        ]
                    },
                    subgrid:{
                        options:{
                            fitColumns:true,
                            foreignField:'pid',
                            singleSelect:true,
                            columns:[[
                                {field:'pnumber',title:'Product Number',width:200},
                                {field:'pname',title:'Product Name',width:200},
                                {field:'supplier',title:'Supplier',width:200}
                            ]],
                            data:[
                                {pnumber:'00100823',pname:'Canon PowerShot A1300',supplier:'Canon'},
                                {pnumber:'12023423',pname:'Cisco RV110W-A-NA-K9',supplier:'Cisco'},
                                {pnumber:'82312393',pname:'Nikon COOLPIX L26 16.1 MP',supplier:'Nikon'}
                            ]
                        }
                    }
                }
            }
        };

Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: September 29, 2015, 08:21:50 PM »

You can call 'getParentGrid' and 'getParentRowIndex' methods to get the parent grid and its row index, then you will be able to get the whole row. Please refer to the code below:
Code:
subgrid:{
    options:{
        fitColumns:true,
        foreignField:'companyid',
        columns:[[
            {field:'orderdate',title:'Order Date',width:200},
            {field:'shippeddate',title:'Shipped Date',width:200},
            {field:'freight',title:'Freight',width:200}
        ]],
        url:'abc.php',
        onBeforeLoad: function(param){
          var dg = $(this).datagrid('getParentGrid');
          var index = $(this).datagrid('getParentRowIndex');
          var row = dg.datagrid('getRows')[index];
          param.price = ...
        }
    },
    ...
}
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!