getColumnState returns NULL

Forum to discuss the new web client version of Servoy.

getColumnState returns NULL

Postby rph » Thu Sep 30, 2021 5:08 pm

Hi

Following situation: We have a "aggrid-groupingtable" on a form and we start the form for the first time (no changes on column width, position or visibility). I call "getColumnState()" on this grid and the result is "NULL". If I change the witdh of a column by 1px or change the position or visibility of one or more columns and call "getColumnState()" again, then I get a JSON-String with all the informations.

Is this a bug or a feature? And if a "feature": why?

My excpectation would be, that "getColumnState()" always deliver the current state of the grid even if it is in the "initial" (design time) state.

Background: On the form are some options that the user can choose from. Depending on the options he choose, some columns should be visible or not. First we've tried to iterate over the columns and set the attribute "visible" to true or false. But in some situations the grid will be reset to the initial (desgin time) state after that. But when we iterate over the JSON that we get from the "getColumnState" function and replace the "hide" property with true or false and then call "restoreColumnState" the current state of the other columns stay as the user defined it. But this "workaround" doesn't work, if we don't get a result from "getColumnState".

Best
Roland

Tested with Servoy 2020.12.1 / Servoy NG Grids 2.7.0
rph
 
Posts: 75
Joined: Wed Aug 10, 2011 11:44 am
Location: Cham, Switzerland

Re: getColumnState returns NULL

Postby paronne » Fri Oct 01, 2021 9:28 am

Hi,

the idea of the getColumnState() is to be able to retrieve and persist any change of the grid done by the end user.
Have you tried to change approach in toggling columns visibility depending on the getColumnState() value ?
- If getColumnState is NULL: it means the state of the grid is already equal to the Design time State; therefore you can change the visible property of the columns.
- If getColumnState has a value instead, you can replace the value of the "hide" property; avoiding the grid to reset it self to the "Design time"

To note, the latest grid Component recently released (v2.8.0) the getColumnState() will always return a value https://support.servoy.com/browse/SVY-16381

Regards,
Paolo
paronne
 
Posts: 202
Joined: Fri Nov 02, 2012 3:21 pm

Re: getColumnState returns NULL

Postby rph » Fri Oct 01, 2021 10:29 am

Hi Paolo

Thanks for your answer!

Your workaround has solved my problem! Thanks a lot for that!

The downside of this is that I have to duplicate my code. One version for the initial state of the grid (getColumnState == null) and the other when there are adjustments on it. And as with any redundancy, I have to make sure that I implement every change everywhere! But at least here it's not that much code!

Best
Roland
rph
 
Posts: 75
Joined: Wed Aug 10, 2011 11:44 am
Location: Cham, Switzerland


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 2 guests