2015-03-18 44 views
0

鉴于下面的查询,我将如何在“salesPriceNo”上创建分层网格,以便父网格显示所有“h”数据并且子网格显示所有“d”数据?我在“通用用户指南”中找到了以下内容,但没有提及WebForms。从单个查询创建分层网格

SELECT h.salesPriceNo, h.customerNo, h.status, h.itemNo, h.salesPersonCode, d.salesPriceDtlNo, d.salesPriceNo, d.itemNo, d.qtyPer, d.unitCost 
FROM salesPriceHeader h LEFT OUTER JOIN salesPriceDetail d ON h.salesPriceNo = d.salesPriceNo 
WHERE h.customerNo = 'MyCustomerNo12345' 

回答

0

Syncfusion ASP.Net Grid控件没有内置支持使用分层网格功能。但我们可以通过网格的DetailsTemplate功能来实现您的要求。详细信息模板功能通过展开行来提供有关每行附加信息的详细视图。

我们可以通过以下方式达到您的要求。请参阅下面的代码片段。

<ej:Grid id="Grid" runat="server" DetailsTemplate="#childgridtemplae">   
    <Columns> 
     <ej:Column Field="salesPriceNo" HeaderText="SalesPrice NO"/> 
     <ej:Column Field="customerNo" HeaderText="Customer No"/>        
     <ej:Column Field="status" HeaderText="Status"/> 
     <ej:Column Field="itemNo" HeaderText="Item No"/> 
     <ej:Column Field="SalesPersonCode" HeaderText="SalesPerson Code"/>       
    </Columns> 
    <ClientSideEvents DetailsDataBound="onDetailsDataBound" /> 
    </ej:Grid> 

在后面的代码中,使用查询获得的数据(有问题)可以分配给父网格,如下所示。

protected void Page_Load(object sender, EventArgs e) 
{ 
this.Grid.DataSource = (DataTable)GetData();//Return data from join operation 
this.Grid.DataBind(); 
} 

在上面你可以看到,顶层电网将包含salesPriceHeader表中的列和detailsTemplate用于显示子网格如下。

<script type="text/x-jsrender" id="childgridtemplae"> 
    <div id="SaleChildGrid{{:salesPriceNo}}" class="e-childgrid" ></div> 
</script> 

子网格的id根据salesPriceNo字段动态生成。

现在在detailsDataBound事件中,子网格将呈现如下。

function onDetailsDataBound(e) { 

     e.detailsElement.find(".e-childgrid").ejGrid({ 
      dataSource: this.model.dataSource, //Parents data source 
      columns: [ 
      { field: "salesPriceDtlNo", headerText: "SalesPrice Dlt No" }, 
      { field: "salesPriceNo", headerText: "SalesPrice No" }, 
      { field: "itemNo", headerText: "Item No" }, 
      { field: "qtyPer", headerText: "Quantity" }, 
      { field: "unitCost", headerText: "Unit Cost" } 
      ] 
     }); 
    } 

在上面的事件处理程序,你可以看到孩子网格包含的列从salesPriceDetail表,还父母数据源,因为在服务器进行连接操作,直接向儿童提供数据源,所以没有过滤在客户端需要获取详细的网格数据。现在,父网格和子网格使用相同的数据源进行渲染,其列为salesPriceHeader(h)显示在父网格中,而salesPriceDetail(d)显示在子网格中。

DetailsTemplate Demo