Skip to main content

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?

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

 


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