Hiding columns in DataGrid2 based on Users Role

3
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...      
asked
1 answers
2

Hi Philipp,

 

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:

 

  1. 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.
  2. Create a new microflow that will be called on change and pass the parent/helper Entity as a parameter.
  3. Open your DataGrid2 properties and go to the Personalization tab.
  4. Select the attribute and microflow created in the configuration section of the Personalization tab.
  5. 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).
  6. Run the project.
  7. Add a breakpoint on this variable.
  8. 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.
  9. In this variable, you will see the configuration of your DataGrid is now available in json format.
  10. 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.
  11. You can then take decision based on the current column being sorted.
  12. Hiding a column can also be done by modifying this json string and reassigning it to the same attribute and committing your object.

 

Hope this helps.

answered