Customization of a Data View

The platform provides a way to alter or extend the data views defined in a BLC.
Note: A data view is a PXSelect BQL expression declared in a BLC for accessing and manipulating data. A data view may contain a delegate, which is an optional graph method that executes when the data view is requested. Every data view is represented by the PXView object and placed in the Views collection of the appropriate BLC. To construct an instance of the PXView class, you use a PXSelect BQL expression and an optional delegate from the highest-level extension discovered.

Suppose that you have declared the Objects data view within the base BLC, as shown below.


 public class BaseBLC : PXGraph<BaseBLC, DAC>
{
    public PXSelect<DAC> Objects;
}

You can alter a data view within a BLC extension in the following ways:

  • By altering the data view within a BLC extension. A data view that is redeclared within a BLC extension replaces the base data view in the Views collection of the BLC instance. Consider the following example of a first-level BLC extension.
    
    public class BaseBLCExt : PXGraphExtension<BaseBLC>
    {
        public PXSelectOrderBy<DAC, 
                   OrderBy<Asc<DAC.field>>> Objects;
    }

    The Views collection of a BLC instance contains the PXView object, which uses the Objects data view declared within the first-level extension, instead of the data view declared within the base BLC.

    Note: A data view redeclared within a BLC extension completely replaces the base data view within the Views collection of a BLC instance, including all attributes attached to the data view declared within the base BLC. You can either attach the same set of attributes to the data view or completely redeclare the attributes.
  • By declaring or altering the data view delegate in a BLC extension. The new delegate is attached to the corresponding data view. Consider the following example of a second-level BLC extension.
    
     public class BaseBLCExtOnExt : PXGraphExtension<BaseBLCExt, BaseBLC>
    {
        protected IEnumerable objects()
        {
            return PXSelect<DAC>.Select(Base);
        }
    }

    The Views collection of a BLC instance contains the PXView object, which uses the Objects data view declared within the first-level extension, with the objects() delegate declared within the second-level extension (see the screenshot below).

    Figure 1. The interaction among the levels of a BLC extension


    To query a data view declared within the base BLC or a lower-level extension from the data view delegate, you should redeclare the data view within a BLC extension. You do not need to redeclare a data member when it is not meant to be used from the data view delegate. Consider the following example of a second-level BLC extension.
    public class BaseBLCExtOnExt : PXGraphExtension<BaseBLCExt, BaseBLC>
    {
        protected IEnumerable objects()
        {
            return Base.Objects.Select();
        }
    }

    The new delegate queries the data view declared within the base BLC. Having redeclared the data view within the first-level extension, you prevent the data view execution from an infinite loop (see the following screenshot).

    Figure 2. The view of the base BLC from the second-level delegate


    Note: If a data view declared within the base BLC contains a delegate, this delegate also gets invoked when the data view is queried from the new delegate (see the following figure).
    Figure 3. The view with the delegate of the base BLC from the second-level delegate