从用户界面动态隐藏选项卡 [英] Hiding a tab from the user interface dynamically

查看:84
本文介绍了从用户界面动态隐藏选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 PXTab 控件的页面,并且想动态显示或隐藏页面上的各个选项卡。如何在运行时控制选项卡的可见性?

I have a page with a PXTab control and want to show or hide individual tabs on the page dynamically. How can I control visibility of tabs at runtime?

推荐答案

您可以通过以下两种方式之一进行操作:

You can do it in one of the following two ways:


  1. 通过在ASPX页面的PXTabItem上设置VisibleExp属性

  2. 通过
    启用/禁用AllowSelect属性在该标签上显示的网格的
    DataMember视图的视图

方法1 – VisibleExp
通过这种方法,您可以直接编写在屏幕的ASPX代码中显示选项卡的条件。

Method 1 – VisibleExp In this method, you directly write the conditions under which the tab should be visible in the screen's ASPX code.

<px:PXTabItem Text="Tax Agency Settings" BindingContext="tab" 
    VisibleExp="DataControls[&quot;chkTaxAgency&quot;].Value = 1">

请注意,绑定上下文很重要,因为它指定了要在VisibleExp中访问的元素的DataControl。
另外,DataControls也是用户界面字段的值的集合,因此您需要在其中指定控件的ID(而不是数据访问类字段)。

Note that the binding context is important as it specifies which element's DataControls you want to access in the VisibleExp. Also DataControls is collection of values for user interface fields, so you need to specify there IDs of controls (not data access class fields).

但是,方法在很多方面都非常受限制:

However, this method is extremely limited in many ways:


  • 条件检查仅限于用户界面中可用的控件
    ,因此它不是可以根据系统的内部状态
    来确定可见性。

  • 有时,此方法将要求您将
    个假数据控件包含到ASPX中,这些控件仅在
    VisibleExp中进行检查,但实际上不会被看到

  • 似乎不支持包括AND / OR在内的复杂条件。

  • 丑陋的& 实体,而不是表达式中的普通引号-尤其是
    可读性不强。

  • The condition checking is restricted to controls available in the UI, so it is not possible to condition visibility upon the internal state of the system.
  • Sometimes this method will require you to include "fake" data controls into ASPX that will only be checked in VisibleExp, but won't actually be ever seen by the user.
  • There seem to be no support for complex conditions including AND/OR.
  • Ugly &quot; entities instead of normal quotes in the expression – not particularly readable.

最重要的是,如果您需要禁用特定文档类型的选项卡,则无法解决-将常量编码为VisibleExp。您将明确编写类似以下内容的代码:VisibleExp = DataControls [ edDocumentType]。Value!= CHK

Most importantly, if you need to disable the tab for a particular document type, there is no way around hard - coding a constant into a VisibleExp. You would be explicitly writing something like: VisibleExp="DataControls["edDocumentType"].Value != CHK"

硬编码通常被认为是非常差的开发实践。这对代码的可维护性构成了重大威胁:可能上述代码将来会破坏某些东西。例如,如果您决定将文档代码从CHK重命名为CHQ。

Hard-coding is generally considered a very poor development practice. It poses a significant threat to code maintainability: probably the above code is going to break something in the future. For example if you decide to rename the document codes form CHK to CHQ.

此外,这种解决方案不容易推广到突然发现需要隐藏选项卡不仅用于检查,还用于其他文档类型。这是由于缺少上述复杂的条件表达式。

In addition to that, this solution is not easily generalized to situations when you suddenly discover the need to hide the tab not only for checks, but also for other document types. This is due to lack of complex conditional expressions mentioned above.

方法2 – AllowSelect
此方法的想法是-如果您隐藏选项卡项中的所有控件,Acumatica会自动隐藏没有可见控件的选项卡。

Method 2 – AllowSelect Idea of this method is - if you hide all controls from the tab item, than Acumatica will automatically hide tab with no visible controls.

举个例子:假设您需要隐藏一个名为Applications的选项卡,具体取决于在SO303000(发票)中选择的文档类型上:

Lets do an example: assume that you need to hide a tab named Applications depending on the document type selected in SO303000 (Invoices):

我们感兴趣的选项卡具有一个网格控件,其数据成员设置为调整:

The tab that we're interested in has a grid control with a data member set to Adjustments:

<px:PXTabItem Text="Applications" RepaintOnDemand="false">
    <Template>
        <px:PXGrid ID="detgrid" DataSourceID="ds" SkinID="Details"> 
            <Levels>
                <px:PXGridLevel DataMember="Adjustments">
                ............
                </px:PXGridLevel>
            </Levels>
        </px:PXGrid> 
    </Template>
</px:PXTabItem>

并非该选项卡项只有一个控件- PXGrid
还请注意此处的必需属性- RepaintOnDemand = false 。此属性指示控件刷新选项卡在显示项目后是否显示内容(和选择数据)。不幸的是,将其设置为false会导致某些性能损失。特别是,调整视图的选择将被更频繁地调用。

And not that this tab item has only one control - PXGrid. Also note required property here - RepaintOnDemand="false". This property indicates whether the control refresh tab items content (and select data) after the item becomes visible. Unfortunately, setting it to false incurs certain performance losses. In particular, the Adjustments view' Select will be called much more frequently.

当前,Tab是智能的,因为它了解当其子控件( PXGridLevel )无法对其数据成员执行选择;在这种情况下,标签会在UI中隐藏自身。这就是为什么您可以通过设置与调整相对应的缓存的 AllowSelect 属性来控制选项卡的可见性的原因:

Currently, the Tab is "smart" in the way that it understands that when its child control (PXGridLevel) cannot perform a select on its data member; in this case, the tab hides itself from the UI. This is why you can control the visibility of the tab by setting the AllowSelect property of the cache that corresponds to the Adjustments:

Adjustments.Cache.AllowSelect = 
    doc.DocType != ARDocType.CashSale 
    && doc.DocType != ARDocType.CashReturn;

上面的代码写在 ARInvoice_RowSelected 图的处理程序,其中 ARInvoice 是主DAC和页面主记录的类型。因此,每次选择 ARInvoice 时,根据文档类型,选项卡项将变为可见或不可见。

The above code is written in the ARInvoice_RowSelected handler of the graph, where ARInvoice is the primary DAC and the type of the master records of the page. So, every time ARInvoice is selected, the tab item will become visible or invisible depending on the document type.

此方法也有其自身的局限性:

This method has its own limitations too:


  • 您应始终记住,禁用
    AllowSelect是不够的,您还应该在需要时启用它。因此,每次调用事件时,您需要
    评估此属性。

  • 如果不将PXTabItem的 RepaintOnDemand
    属性设置为false,该方法似乎不起作用(见上文)。 / li>
  • You should always remember that it is not enough to disable AllowSelect, you should also enable it when needed. So you need to evaluate this property every time when event is called.
  • This method doesn't seem to work without setting the PXTabItem's RepaintOnDemand property to false (see above).

来源: http://asiablog.acumatica.com/2016/05/hiding-tab-from-user-interface.html

这篇关于从用户界面动态隐藏选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆