[OutSystems Data Grid] Hide a Column if there are no values in a column
data-grid-reactive
Reactive icon
Forge component by Platform Maintenance
Application Type
Reactive

Is it possible to conditionally hide a column when there is no data contained within it? I know it is possible to set this manually on the columns by using the column components (by setting the "Visible" parameter to false), however, I want to do this conditionally. If all values for a given row are empty, hide, otherwise show. For context, we're using the columns that the Datagrid provides and it is not auto generated and fetching data from a REST endpoint that we are then mapping to a structure list which we then passing to the ArrangeData action.

Can you perhaps do this with javascript using the GridAPI? I'd rather not loop over every structure attribute in outsystems to check every time since that would be costly. 

Thanks in advance!

Hi Gert,

in that case we have to move away from lowcode, and add a little regex magic, I think.

See attached oml, there is a client action that takes in the JSON that serves as input for the grid (coming out of ArrangeData) and takes in the attribute name as it appears in the json (the same you have to use as binding for your grid column), and returns a boolean saying if any value is filled.

This action is defined as a function, so you can use it directly in the visible property of your datagrid column widget.


see attached the modified oml,

Dorine

EDIT : you might have to improve a little on this to also work for other than text attributes, I think.

QDR_HideEmptyGridColumns.oml

Hi Gert,

if you need the information whether for a given column all cells are empty or not, somebody is going have to do the act of looking at each value (at least until the first non-empty is found), either in your code or in a function you are calling, or a feature of the Grid itself, or (possibly the most performant) in the database.

As you are working off a REST api, the last option is probably out of reach for you.  

I don't know all features of the grid, but looking at this post about the underlying wijmo grid, there probably is nothing available there, as the suggestion there also is to iterate until first non empty is found.

If you are working with self-defined columns, and not auto column, that means that you know at design time what columns you are interested in.  If these are not too many, you could add a boolean for each column, and after you have filled the structure list with data from the rest service, somewhere near the spot where you do the ArrangeData, also do a listIndexOf for each column, with condition of not being empty, and set the corresponding boolean.  And use that boolean as the Visible property of that column.

See attached oml to get the idea, I don't have a structure list, but that doesn't change the ListIndex  and boolean logic.  Don't look at the switch and the local booleans in my example, they are just a way for me to create test data.

Dorine

QDR_HideEmptyGridColumns.oml

Hey Dorine,


Many thanks for your reply!


I should probably have mentioned this in the original post, but I have an implementation and it is done as you say, loop over and used the "ListIndexOf" function and then check if it returns -1. What I wanted to achieve is for some way to standardize it so I don't have to repeat myself, since the datagrid component is used in many web blocks that each fetch their own data through their own REST endpoints.


Gert

Hi Gert,

in that case we have to move away from lowcode, and add a little regex magic, I think.

See attached oml, there is a client action that takes in the JSON that serves as input for the grid (coming out of ArrangeData) and takes in the attribute name as it appears in the json (the same you have to use as binding for your grid column), and returns a boolean saying if any value is filled.

This action is defined as a function, so you can use it directly in the visible property of your datagrid column widget.


see attached the modified oml,

Dorine

EDIT : you might have to improve a little on this to also work for other than text attributes, I think.

QDR_HideEmptyGridColumns.oml

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.