DataGrid advanced -- subgrid

Source: Internet
Author: User

Subgrid, that is, a new layer of DataGrid in the DataGrid, is suitable for displaying data with layers. For example, to display a batch of orders, the Order contains specific goods. Subgrid can be used for such a requirement.

We can first look at the official website subgrid to enhance our visual experience.


How to implement it? It is still simple to show the data.

The amount of DEMO code is just dozens of lines, which is easy to understand.

        $(function(){            $('#dg').datagrid({                view: detailview,                detailFormatter:function(index,row){                    return '<div style="padding:2px"><table class="ddv"></table></div>';                },                onExpandRow: function(index,row){                    var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');                    ddv.datagrid({                        url:'datagrid22_getdetail.php?itemid='+row.itemid,                        fitColumns:true,                        singleSelect:true,                        rownumbers:true,                        loadMsg:'',                        height:'auto',                        columns:[[                            {field:'orderid',title:'Order ID',width:200},                            {field:'quantity',title:'Quantity',width:100,align:'right'},                            {field:'unitprice',title:'Unit Price',width:100,align:'right'}                        ]],                        onResize:function(){                            $('#dg').datagrid('fixDetailRowHeight',index);                        },                        onLoadSuccess:function(){                            setTimeout(function(){                                $('#dg').datagrid('fixDetailRowHeight',index);                            },0);                        }                    });                    $('#dg').datagrid('fixDetailRowHeight',index);                }            });        });

1. To use this subgrid view, you need to use the datagrid-detailview.js provided on the official website, which helps us define the display view of detailview.

During use, we only need to replace the default view with detailview in the main DataGrid.

2. detailformatter, that is, the initial code in the generated detail. Put a table here and then dynamically create it as a DataGrid.

3. When the primary DataGrid Initialization is complete, the subgrid is not displayed. At this time, the subgrid does not exist and we will not create it.

When will it be created? When we expand a piece of data in the primary DataGrid, that is, in the onexpandrow event, we create a subgrid under its "jurisdiction.

4. The method for creating a subgrid is similar to that for creating a DataGrid, but some fixdetailrowheight operations are added later.

Fixdetailrowheight this method is mainly used to adjust the height of the subgrid. If it is not added, the height of the subgrid may be misplaced.


But here the setTimeout time is 0. What is the difference between it and the direct function call?

DataGrid advanced -- subgrid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.