Flexgrid save column order and size

Posted by: fsegui on 26 October 2021, 7:37 am EST

    • Post Options:
    • Link

    Posted 26 October 2021, 7:37 am EST

    Hi,

    I have a C1FlexGrid component binded to my database. The user can reorder the columns and also change the width.

    I want to save these informations when closing the app and reapply them when the user starts it again.

    I’ve checked the SaveGrid method but it also save the data, which is very long when loading it back.

    Is there another way? Or do I have to create a routine from scratch?

    Thanks

  • Posted 27 October 2021, 12:23 am EST

    Hi,

    You can build a string that persists the column state (order, width, etc.) of the grid by using the BuildString method of the ColumnCollection class. You can save this string in a file or settings and restore the column state using the ParseString method of the ColumnCollection class.

    We have attached a sample showing the same.

    You can refer to the links below for any information regarding these methods.

    BuildString : https://www.grapecity.com/componentone/docs/win/online-flexgrid/C1.Win.C1FlexGrid.4.5.2~C1.Win.C1FlexGrid.ColumnCollection~BuildString.html

    ParseString : https://www.grapecity.com/componentone/docs/win/online-flexgrid/C1.Win.C1FlexGrid.4.5.2~C1.Win.C1FlexGrid.ColumnCollection~ParseString.html

    Please let us know if you need any other information.

    Regards,

    Avnish

    SaveColumnState.zip

  • Posted 27 October 2021, 2:14 am EST

    Hi Avnish

    Thanks, that works fine.

    Regards

  • Posted 18 January 2022, 1:33 pm EST

    Hi Avnish,

    I’ve used your method but I encountered one issue, if the grid has hidden columns at loading (when creating the grid, I’m setting some columns not visible but I’m letting the user showing them if needed), when restoring the layout with ParseString does not switch those columns visible.

  • Posted 19 January 2022, 2:14 am EST

    Hi,

    We do not see any issues at our end. If the column was visible at the time, the state was saved, the column will get visible when you restore the state. Please refer to the sample attached.

    Regards

    Avnish

    SaveColumnState_mod.zip

  • Posted 19 January 2022, 4:29 am EST

    Hi,

    Does the includeDefault could have an impact?

    I’ve changed and set it to true, now it works.

    Thanks

  • Posted 20 January 2022, 6:47 am EST

    Hi,

    Good to hear that it works now. If the includeDefault is set to true, the BuildString method saves the default values of the Columns in the description string, which includes the value of the Visible property also.

    If you need any other help, please feel free to ask.

    Regards,

    Prabhat Sharma.

  • Posted 18 February 2022, 11:07 am EST

    Hi,

    I’m encountering a new use case for this.

    Let’s say my app has 5 columns. The user can save the order, visible status… with the BuildString method.

    I’m then publishing a new version of my app where I add a new column, but not at the end.

    When the user starts the app & restore the layout, this new column is “overwritten” by the parseString method. Thus my app could disfunction.

    Is there a way to reapply the layout taking into account new columns?

    Thanks

    Regards

    Florent

  • Posted 21 February 2022, 12:50 pm EST

    Hi Florent,

    Unfortunately, there is no direct way of implementing this as the ParseString method overrides the current column state. As a workaround, you can save the required column info of the newly added column before restoring the saved column state and then manually add the new column again according to the info you saved previously after restoring the column state.

    Regards.

    Avnish

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels