This is a migrated thread and some comments may be shown as answers.

radgrid with auto generated columns with persistence framework

1 Answer 116 Views
Persistence Framework
This is a migrated thread and some comments may be shown as answers.
jeeno
Top achievements
Rank 1
jeeno asked on 06 Oct 2017, 08:44 AM
Is it possible to use persistence framework to persist column settings when the radgrid is set AutoGeneratedColumns =true? 

1 Answer, 1 is accepted

Sort by
0
Marc
Top achievements
Rank 1
answered on 28 Feb 2018, 06:41 PM

Yes. The grid will pick up the settings for autogenerated columns if the latter is loaded in the former's DataBound event. The hidden columns need to be forced to render by setting Visible = true to them. Once rendered, the columns that are hidden on load would have a negative width. An additional css rule for the columns forcing a min-width to them is required.

private void Grid_DataBound(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        LoadPersistenceManagerState();
        // Skip the first two columns that are Telerik-generated
        var autogeneratedColumnsFromDataSource = ((RadGrid)sender).MasterTableView.RenderColumns.Skip(2);
        // Force all columns to be rendered in markup, including those hidden after loading the state
        foreach (var column in autogeneratedColumnsFromDataSource)
        {
            column.Visible = true;
        }
    }
}

 

[id$="Grid"] .CustomColumnCssClass, [id$="Grid"] .rgDataDiv td {
    min-width: 150px;
    width: 1px; /* Force hidden columns with negative width to respect min-width */
}

Tags
Persistence Framework
Asked by
jeeno
Top achievements
Rank 1
Answers by
Marc
Top achievements
Rank 1
Share this question
or