Hiding Data Grid 2 when no data

2
I’d like to hide my data grid when no items exist within the data. The grid uses a microflow to retrieve data within a view model. Is there a mechanism of interrogating a list for items within the expression builder? An isEmpty, Count, etc. function perhaps?
asked
2 answers
1

Not too sure on the use case here.

 

The datagrid 2 widget already allows you to add a custom empty message if no data is found and would recommend using this.

 https://docs.mendix.com/appstore/modules/data-grid-2/#51-empty-list-message

 

If you really want to hide the whole table:

- Create a non persistent entity associated to your data entity.

- Have an attribute of a calculated field that retrieves the list by how you data grid 2 would normally retrieve and uses list agregation to count it and return as the value.

- Wrap your d2 in a data view object that creates this np entity.

- Then in the d2 visibility option you should be able to see the wrapped objects calculated value and do something like “$dataview1/Count != 0”

 

answered
2

You can set the datagrid2 “Empty Message” to custom which adds a class to the html when your data grid is empty.  Then you can use the selector :has() 

 

It is supported in Chrome, Edge and Safari at the moment.  I have a couple use cases like this where I utilize the following css:

 

    .datagridcustomclass:has(.empty-placeholder) {
        display: none;
    }

Add “datagridcustomclass” to your datagrid 2 and your set

answered