radgrid with auto generated columns with persistence framework

2 posts, 0 answers
  1. jeeno
    jeeno avatar
    1 posts
    Member since:
    Oct 2017

    Posted 06 Oct 2017 Link to this post

    Is it possible to use persistence framework to persist column settings when the radgrid is set AutoGeneratedColumns =true? 
  2. Marc
    Marc avatar
    5 posts
    Member since:
    May 2015

    Posted 28 Feb in reply to jeeno Link to this post

    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 */
    }

Back to Top