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

Capturing Column Settings on Postback

4 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 12 Jun 2014, 05:04 AM
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!

4 Answers, 1 is accepted

Sort by
0
Erik
Top achievements
Rank 1
answered on 12 Jun 2014, 05:06 AM
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).
0
Princy
Top achievements
Rank 2
answered on 12 Jun 2014, 06:20 AM
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
0
Erik
Top achievements
Rank 1
answered on 14 Jun 2014, 05:30 AM
Great!  That's exactly what I needed.  Thank you.
0
DogBizPro
Top achievements
Rank 1
answered on 11 Oct 2017, 12:07 AM
What am I missing? The server code is not being called for me.
Tags
Grid
Asked by
Erik
Top achievements
Rank 1
Answers by
Erik
Top achievements
Rank 1
Princy
Top achievements
Rank 2
DogBizPro
Top achievements
Rank 1
Share this question
or