Solved

Keeping grid column position for a column added in code

  • 15 May 2024
  • 2 replies
  • 43 views

Userlevel 4
Badge +2

If a grid column is added within code, is there a way to get its column position to persist after a user moves it - like any other grid column? I'm adding the column to the grid in the Page_Load event in a graph extension, but it doesn't seem to magically know what position it was moved like the others because it is being added each time. Could there be a setting I'm missing, or would I have to roll my own position persistence to get this to work?

icon

Best answer by Zoltan Febert 15 May 2024, 02:29

View original

2 replies

Userlevel 6
Badge +3

Hi @Tony Lanzer 

Most likely your column is not registered in the GridPreferences table.
I didn’t try it, but probably you can register it in the Page_Load event something like this:

var gridPreferences = GridPreferences.Get("SCREEN_ID", "UserName", "ViewName").ToList();

if (gridPreferences.FirstOrDefault(it => it.DataField == "dataField") == null) {
gridPreferences.Add(new GridPreferences.ColumnPref(
dataField: "dataField",
visible: true,
order: 0,
width: 50)
);
GridPreferences.Set("SCREEN_ID", "UserName", "ViewName", gridPreferences.ToArray());
}

 

Userlevel 4
Badge +2

Thanks @Zoltan Febert!  That’s exactly what I needed to help get it working.  Since I’m adding the column to the grid on page load, I now use GridPreferences.Get() to get the last grid position (order), then insert the column into the grid at that position and it behaves as I need.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved