Capturing Column Settings on Postback

5 posts, 0 answers
  1. Erik
    Erik avatar
    6 posts
    Member since:
    Aug 2012

    Posted 12 Jun 2014 Link to this post

    I'd like to persist the column display settings for my grid to a database.  I'm using the header context menu to allow the users to show/hide fields, but am having trouble figuring out how to capture which are visible.  I've placed a button at the top of my page for them to click.  When I inspect the columns after post-back, the column display settings are not present.  Is there a way to do this?

    Thanks!
  2. Erik
    Erik avatar
    6 posts
    Member since:
    Aug 2012

    Posted 12 Jun 2014 in reply to Erik Link to this post

    Forgot to mention that the display settings are present in the grid object, but they are not current (reflecting the changes the user has made client side).
  3. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Jun 2014 in reply to Erik Link to this post

    Hi Erik,

    Please take a look at the sample code snippet which shows the column hidden and shown.

    ASPX:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
    </telerik:RadAjaxManager>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function columnDisplayChanged(sender, args) {
                var colUniqueName = args.get_gridColumn().get_uniqueName();
                $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest(colUniqueName + "display");
            }
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1" EnableHeaderContextMenu="true" AllowPaging="true">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
                <telerik:GridBoundColumn DataField="ShipVia" HeaderText="ShipVia" UniqueName="ShipVia" />
                <telerik:GridBoundColumn DataField="ShipCountry" HeaderText="ShipCountry" UniqueName="ShipCountry" />
                <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" UniqueName="CustomerID" />
                <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID" />
            </Columns>
        </MasterTableView>
        <ClientSettings>
            <ClientEvents OnColumnHidden="columnDisplayChanged" OnColumnShown="columnDisplayChanged" />
        </ClientSettings>
    </telerik:RadGrid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT  * FROM [Orders]"></asp:SqlDataSource>

    C#:
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
      if (e.Argument.IndexOf("display") != -1)
      {
       string colUniqueName = e.Argument.Substring(0, e.Argument.IndexOf("display"));
       GridColumn hiddenColumn = RadGrid1.MasterTableView.GetColumnSafe(colUniqueName) as GridColumn;
       RadAjaxManager1.Alert(colUniqueName + " display - " + hiddenColumn.Display);
      }
    }

    Thanks,
    Princy
  4. Erik
    Erik avatar
    6 posts
    Member since:
    Aug 2012

    Posted 14 Jun 2014 in reply to Princy Link to this post

    Great!  That's exactly what I needed.  Thank you.
  5. DogBizPro
    DogBizPro avatar
    158 posts
    Member since:
    Aug 2013

    Posted 10 Oct 2017 Link to this post

    What am I missing? The server code is not being called for me.
Back to Top