How to dynamically hide entire column in datgrid2?

1
Hi , I want to dynamically hide entire column based on some condition in data grid2. Thanks in advance.
asked
4 answers
1

Hello everyone,

 

Hiding a column dynamically is possible in DataGrid2.

 

Example: You have 4 columns in your DataGrid2 and the requirement is to hide the 4th column when the data is sorted by first two columns and make it visible again when the data is sorted by 3rd column.

 

If this is what you mean by dynamically hiding the column, then please read below:

 

  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.

I will be creating a video tutorial soon on this topic and will share the link here in future.

 

Hope this helps.

answered
0

Hi Nisha,

have a look at section 2.4 in the datagrid2 documentation https://docs.mendix.com/appstore/modules/data-grid-2/#24-hiding

 

answered
0

Hi Nisha,

 

I do not know, whether the existing answers apply to your question. Yes, you can “manually” hide columns using the “eye” button. In my understanding, “dynamically” means that you can control the hiding of the column using data. That is exactly what I am trying to do and why I found this post. 

 

As far as I can see, that cannot be done. You can dynamically set the class for a cell, but this would at best empty the column, not hide it. When you have only one or two columns that needs to be hidden dynamically, you can place multiple datagrids in your container (with and without said columns). Depending on your data, you could make only one datagrid visible at any given point in time. For more hideable columns this would become very ugly very fast. 

 

Correct me if I am wrong, but the only other potential option I can see, would be to somehow “press” the eye button programmatically, but I do not know, whether this can be done, actually.

 

 

answered
0

Resurrecting an old thread a bit but with the later versions of Datagrid 2 this can now be done on a per-column basis with expressions and works very well

answered