【发布时间】:2018-03-13 19:17:20
【问题描述】:
我正在开发一个自定义页面,通过以分层顺序显示表数据来可视化父记录和子记录之间的关系。
我的 BLC 中有 2 个数据视图,我想将其用作两个 PXGrids 的数据源,以主/明细格式显示数据。在主网格中选择一条记录后,所有相关的子条目都应显示在详细信息网格中。
我应该如何在 Aspx 中声明我的 2 个 PXGrids 来完成这项任务?
【问题讨论】:
我正在开发一个自定义页面,通过以分层顺序显示表数据来可视化父记录和子记录之间的关系。
我的 BLC 中有 2 个数据视图,我想将其用作两个 PXGrids 的数据源,以主/明细格式显示数据。在主网格中选择一条记录后,所有相关的子条目都应显示在详细信息网格中。
我应该如何在 Aspx 中声明我的 2 个 PXGrids 来完成这项任务?
【问题讨论】:
例如,如果某些 BLC 包含 Categories 数据视图和 Related Products 数据视图,您可以将 Categories 视图指定为主网格的数据源和 Products 视图作为详细信息网格的数据源。在主网格中选择一个类别后,与该类别关联的所有产品都将显示在产品数据视图的详细信息网格中。
public class ProductCategories : PXGraph<ProductCategories>
{
#region Actions
public PXSave<Category> Save;
public PXCancel<Category> Cancel;
#endregion
#region Data Members
public PXSelect<Category> Categories;
public PXSelect<CategoryProduct,
Where<CategoryProduct.categoryID,
Equal<Current<Category.categoryID>>>> CategoryProducts;
#endregion
#region Event Handlers
protected virtual void Category_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
this.CategoryProducts.Cache.AllowInsert = e.Row != null;
}
#endregion
}
如上面的代码 sn-p 所示,详细视图通过 Current BQL 运算符与主视图引用。此外,请注意为 Category DAC 定义的 RowSelected 事件处理程序,如果主文件中没有单个记录,则禁用详细信息网格上的 Insert 按钮网格。
下一步是在 Aspx 中配置 master-detail PXGrids:
为主网格设置 SyncPosition 属性为 true,然后定义 AutoCallBack 和 OnChangeCommand 属性如下,每次在主网格中选择不同的记录或根本不选择记录时相应地刷新详细信息网格:
<px:PXGrid ID="masterGrid" runat="server" DataSourceID="ds" SkinID="Details"
SyncPosition="True" Caption="Categories" CaptionVisible="True" Width="100%">
<AutoCallBack Command="Refresh" Target="detailGrid" />
<OnChangeCommand Command="Refresh" Target="detailGrid" />
...
</px:PXGrid>
对于细节网格,只需要定义一个 Refresh 回调命令来强制主网格选择数据以及细节网格。通过这样做,框架将引发先前定义的 Category_RowSelected 事件处理程序,并在主网格中没有记录的情况下禁用详细信息网格上的 Insert 按钮:
<px:PXGrid ID="detailGrid" runat="server" DataSourceID="ds" SkinID="Details"
Caption="Products" CaptionVisible="True" Width="100%">
<CallbackCommands>
<Refresh SelectControlsIDs="masterGrid" />
</CallbackCommands>
...
</px:PXGrid>
为了更好的用户体验,建议将主从 PXGrids 放在 PXSplitContainer 中,如下面的代码 sn-p 所示:
<px:PXSplitContainer runat="server" ID="sp" PositionInPercent="true" SplitterPosition="50"
SkinID="Horizontal" Orientation="Horizontal" Panel1MinSize="250" Panel2MinSize="250">
<AutoSize Enabled="true" Container="Window" />
<Template1>
<px:PXGrid ID="masterGrid" runat="server" DataSourceID="ds" SkinID="Details"
SyncPosition="True" Caption="Categories" CaptionVisible="True" Width="100%">
<AutoCallBack Command="Refresh" Target="detailGrid" />
<OnChangeCommand Command="Refresh" Target="detailGrid" />
<Levels>
<px:PXGridLevel DataMember="Categories">
<Columns>
...
</Columns>
</px:PXGridLevel>
</Levels>
<AutoSize Enabled="True" />
</px:PXGrid>
</Template1>
<Template2>
<px:PXGrid ID="detailGrid" runat="server" DataSourceID="ds" SkinID="Details"
Caption="Products" CaptionVisible="True" Width="100%">
<CallbackCommands>
<Refresh SelectControlsIDs="masterGrid" />
</CallbackCommands>
<Levels>
<px:PXGridLevel DataMember="CategoryProducts">
<Columns>
...
</Columns>
</px:PXGridLevel>
</Levels>
<AutoSize Enabled="True" />
</px:PXGrid>
</Template2>
</px:PXSplitContainer>
以下是主详细信息 PXGrids 在 Acumatica 网页中的外观和操作方式:
【讨论】: