Skip to main content
Solved

Keeping grid column position for a column added in code


Tony Lanzer
Semi-Pro III
Forum|alt.badge.img+1

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?

Best answer by Zoltan Febert

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());
}

 

View original
Did this topic help you find an answer to your question?

2 replies

Zoltan Febert
Jr Varsity I
Forum|alt.badge.img+3
  • Jr Varsity I
  • 176 replies
  • Answer
  • May 15, 2024

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());
}

 


Tony Lanzer
Semi-Pro III
Forum|alt.badge.img+1
  • Author
  • Semi-Pro III
  • 79 replies
  • May 15, 2024

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings