Maxime
Maxime

Reputation: 858

Hide grid columns dynamically

I'm trying to hide columns in a grid tab dynamically, it works fine until the user goes into the column configurations and decides to show the columns.

Once the user does that, my code doesn't affect the columns visibility anymore.

As a POC I tried doing this :

   public PXAction<POOrder> HIDEFIELDS;
    [PXUIField(DisplayName = "hide fields")]
    [PXButton(CommitChanges = true)]
    public virtual void hIDEFIELDS()
    {
        PXUIFieldAttribute.SetVisible<POLineExt.usrFinalDestination>(Base.Transactions.Cache, null, false);
        PXUIFieldAttribute.SetVisible<POLineExt.usrDateExportation>(Base.Transactions.Cache, null, false);
        PXUIFieldAttribute.SetVisible<POLineExt.usrContainerNbr>(Base.Transactions.Cache, null, false);
    }

public PXAction<POOrder> Showfields;
[PXUIField(DisplayName = "showfields")]
[PXButton(CommitChanges = true)]
public virtual void showfields()
{
    PXUIFieldAttribute.SetVisible<POLineExt.usrFinalDestination>(Base.Transactions.Cache, null, true);
    PXUIFieldAttribute.SetVisible<POLineExt.usrDateExportation>(Base.Transactions.Cache, null, true);
    PXUIFieldAttribute.SetVisible<POLineExt.usrContainerNbr>(Base.Transactions.Cache, null, true);
}

http://recordit.co/5lYGmjOjHl

How do I prevent this behaviour ? what is the difference between PXUIFieldAttribute.SetVisible and PXUIFieldAttribute.SetVisibility ?

Upvotes: 1

Views: 1459

Answers (1)

Hugues Beaus&#233;jour
Hugues Beaus&#233;jour

Reputation: 8278

The Visible property determines if the column is visible in the grid (form, tree etc..) and the Visibility property determines if the column is visible in the grid column configuration dialog.

As you found out, the user can override the Visible=False property by using the user-defined grid column configuration.

To prevent the user overriding the Visible property you have to set both Visible and Visibility.

PXCache cache = Base.Transactions.Cache;
PXUIFieldAttribute.SetVisibility<POLineExt.usrFinalDestination>(cache, null, PXUIVisibility.Invisible);
PXUIFieldAttribute.SetVisible<POLineExt.usrFinalDestination>(cache, null, false);

Your code suggest you want to make this a dynamic change but I think the Visibility property only support static change. By static I mean that the call will work only once when the page load and it will ignore subsequent calls. The convention is to put these calls in the Initialize() method override for graph extensions or the constructor of new custom graph:

public override void Initialize()
{
    // Extend base graph to set visibility property here.
}

Upvotes: 3

Related Questions