Hide tab from user interface dynamically

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

+5
source share
1 answer

You can do this in one of two ways:

  • By setting the VisibleExp property to PXTabItem on an ASPX page
  • By turning on / off the AllowSelect property for the view, which serves as the DataMember grid displayed on this tab

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

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

Note that the binding context is important, as it indicates which DataControls element you want to receive in VisibleExp. DataControls is also a set of values ​​for user interface fields, so you need to specify the identifiers of the controls there (and not the fields of the data access class).

However, this method is extremely limited in many ways:

  • Condition checking is limited to the controls available in the user interface, so it is not possible to set visibility in the internal state of the system.
  • Sometimes this method requires you to enable "fake" data controls in ASPX, which will only be checked in VisibleExp, but in fact the user will never see it.
  • There seems to be no support for complex conditions, including AND / OR.
  • Ugly &quot; objects instead of the usual quotes in the expression - not particularly readable.

Most importantly, if you need to disable the tab for a specific type of document, there is no way to hard code the constant in VisibleExp. You would explicitly write something like: VisibleExp = "DataControls [" edDocumentType "]. Value! = CHK"

Hard coding is generally considered a very bad development practice. This poses a significant threat to maintainability of the code: perhaps the above code will break something in the future. For example, if you decide to rename document codes from CHK to CHQ.

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

Method 2 - AllowSelect The idea of ​​this method is that if you hide all the controls from the tab control, Acumatica will automatically hide the tab without any visible controls.

Let's make an example: suppose you need to hide a tab with the name of the Application depending on the type of document selected in SO303000 (Invoices):

The tab that interests us has a grid control with the data item set in 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> 

And not that this tab element has only one control - PXGrid . Also pay attention to the required property here - RepaintOnDemand="false" . This property indicates whether the control's update item will update the content of the item (and select data) after the item becomes visible. Unfortunately, setting this parameter to false leads to certain performance losses. In particular, viewing the β€œChoice” settings will be called up much more often.

The tab is currently smart in the sense that it understands that when a child control ( PXGridLevel ) cannot make a selection in its data element; in this case, the tab is hidden from the user interface. That's why you can control the visibility of a tab by setting the AllowSelect property of the cache, which matches the settings:

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

The above code is written in the ARInvoice_RowSelected graphics handler, where ARInvoice is the primary DAC and the type of page master records. Thus, each time ARInvoice selected, the tab element becomes visible or invisible depending on the type of document.

This method also has its own limitations:

  • You should always remember that disabling AllowSelect is not enough; you must also enable it when necessary. Therefore, you need to evaluate this property every time an event is raised.
  • This method does not seem to work without setting the PXTabItem RepaintOnDemand property false (see above).

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

+7
source

All Articles