We need to hide a column based on the Users “UserRole” – e.g. only show a specific column only if the User is an Admin. DataGrid2 supports hiding columns from Users point of view, but there is no specific UserRole checkbox available. Is there any functionality to achieve this? We already tried dynamic classes (including css classes with “display:none”), but it only applied for the cells and NOT the whole column...
You can do this by having a default config in the parent object or a helper object of the list that is displayed in the DataGrid2.
Example: OrderListHelper Entity can be a parent entity or Order Entity. Association: 1-*. Attribute name: ConfigHelper.
You can save the default config in json format. You can also dynamically hide/show columns based on the changes done to data of DataGrid2.
You can use the following steps to find config format of your DataGrid2.
Full steps on how to debug and implement dynamically hiding columns:
Create a new attribute of type String(Unlimited) in the parent object or a helper object of the list that is displayed in the DataGrid2.
Example: OrderListHelper Entity can be a parent entity or Order Entity. Association: 1-*. Attribute name: SortConfigHelper.
Create a new microflow that will be called on change and pass the parent/helper Entity as a parameter.
Open your DataGrid2 properties and go to the Personalization tab.
Select the attribute and microflow created in the configuration section of the Personalization tab.
Go to the on change microflow and create a new variable of type string and assign value of the new attribute to this variable(Helps in debugging).
Run the project.
Add a breakpoint on this variable.
Sort any column on your DataGrid2 and you will see this microflow being executed and debugger has stopped on your Create Variable activity. Step Over.
In this variable, you will see the configuration of your DataGrid is now available in json format.
Here onwards, you can use several different approaches to read and modify this json string. I like to use import map and create objects of this config data.
You can then take decision based on the current column being sorted.
Hiding a column can also be done by modifying this json string and reassigning it to the same attribute and committing your object.