[CLOSED] [1.0] How to save Gridpanel Column configuration to Cookie?

  1. #1

    [CLOSED] [1.0] How to save Gridpanel Column configuration to Cookie?


    Suppose a user hides/shows a column or changes the column width, can this change be saved on a cookie and then be reloaded the next time the user logs in? Do you have a sample code for it? Thanks much!

  2. #2

    Please set StateProvider="Cookie" for ResourceManager and set ColumnID for each grid's column
    Vladimir Shcheglov
    Sr. Developer
  3. #3
    Hi Vlad,

    Thanks for the response.

    I followed your suggestion, set the StateProvider to 'cookie' and set columnIDs for each columns. I hide the Price column, and hit refresh on the browser. After refresh, the price column still appears. What I am trying to accomplish is the price should not be displayed after refresh as I had hidden it prior to refresh. Is this doable? Maybe I am missing something here, and your help would be greatly appreciated

    Here's my code:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
            if (!X.IsAjaxRequest)
                this.Store1.DataSource = new List<Company> 
                    new Company(0, "3m Co", "", 71.72, 0.02, 0.03),
                    new Company(1, "Alcoa Inc", "", 29.01, 0.42, 1.47),
                    new Company(2, "Altria Group Inc", "", 83.81, 0.28, 0.34),
                    new Company(3, "American Express Company","",  52.55, 0.01, 0.02),
                    new Company(4, "American International Group, Inc.", "", 64.13, 0.31, 0.49),
                    new Company(5, "AT&T Inc.", "", 31.61, -0.48, -1.54),
                    new Company(6, "Boeing Co.", "", 75.43, 0.53, 0.71),
                    new Company(7, "Caterpillar Inc.", "", 67.27, 0.92, 1.39),
                    new Company(8, "Citigroup, Inc.","",  49.37, 0.02, 0.04),
                if (!this.IsPostBack)
                    RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
                    sm.SelectedRow = new SelectedRow(2);
                    sm.SelectedRows.Add(new SelectedRow(2));
                    sm.SelectedRows.Add(new SelectedRow("11"));
        protected void Button2_Click(object sender, DirectEventArgs e)
            StringBuilder result = new StringBuilder();
            result.Append("<b>Selected Rows</b></br /><ul>");
            RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
                result.Append("<li>" + row.RecordID + "</li>");
            this.Label1.Html = result.ToString();
        public class Company
            public Company(int id, string name, string description, double price, double change, double pctChange)
                this.ID = id;
                this.Name = name;
                this.Price = price;
                this.Change = change;
                this.PctChange = pctChange;
            public int ID { get; set; }
            public string Name { get; set; }
            public string Description { get; set; }
            public double Price { get;set; }
            public double Change { get;set; }
            public double PctChange { get;set; }
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>GridPanel with Checkbox Selection Model - Ext.NET Examples</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />    
        <script type="text/javascript">
            var template = '<span style="color:{0};">{1}</span>';
            var change = function (value) {
                return String.format(template, (value > 0) ? "green" : "red", value);
            var pctChange = function (value) {
                return String.format(template, (value > 0) ? "green" : "red", value + "%");
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" StateProvider="Cookie" />
            <h1>GridPanel with Checkbox Selection Model</h1>
            <ext:Store ID="Store1" runat="server">
                    <ext:JsonReader IDProperty="ID">
                            <ext:RecordField Name="ID" />
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="Description" />
                            <ext:RecordField Name="Price" />
                            <ext:RecordField Name="Change" />
                            <ext:RecordField Name="PctChange" />
                Title="Company List"
                Height="350" ClicksToEdit="2">
                <ColumnModel ID="ColumnModel1" runat="server">
                        <ext:Column ColumnId="Company" Header="Company" Width="160" DataIndex="Name" Resizable="false" MenuDisabled="true" Fixed="true" />
                        <ext:Column ColumnID="Price" Header="Price" Width="75" DataIndex="Price">
                            <Renderer Format="UsMoney" />
                        <ext:Column ColumnID="Description" Header="Description" DataIndex="Description">
                                <ext:TextField ID="txtDescription" runat="server">
                                        <KeyUp Handler="alert('test')"; />
                        <ext:Column ColumnID="Change" Header="Change" Width="75" DataIndex="Change">
                            <Renderer Fn="change" />
                        <ext:Column ColumnID="PctChange" Header="Change" Width="75" DataIndex="PctChange">
                            <Renderer Fn="pctChange" />
                    <ext:PagingToolbar ID="PagingToolBar1" runat="server" PageSize="10" StoreID="Store1" DisplayInfo="false" />
                    <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" />
                    <ext:Button ID="Button2" runat="server" Text="Submit Selected Records">
                            <Click OnEvent="Button2_Click">
                                <EventMask ShowMask="true" />
            <div style="width:590px; border:1px solid gray; padding:5px;">
                <ext:Label ID="Label1" runat="server" />
  4. #4

    Yes, latest ExtJS has a bug which prevents restore the state. Fixed in SVN
    If you don't want to update from SVN then add the following code to the page head
    <ext:ResourcePlaceHolder runat="server" Mode="ScriptFiles"/>
    <script type="text/javascript">
          setState : function(col, state) {
             Ext.applyIf(this.lookup[col], state);
    Vladimir Shcheglov
    Sr. Developer
  5. #5
    Hi Vlad,

    It works! Thank you so much for this. Please mark as solved.


Similar Threads

  1. Replies: 2
    Last Post: Apr 07, 2012, 6:40 AM
  2. [CLOSED] Cookie Provider - how to limit cookie size?
    By voipswitch in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Aug 12, 2011, 1:47 PM
  3. Replies: 1
    Last Post: Jul 27, 2011, 10:19 AM
  4. [CLOSED] GridPanel Column Size Restore from Cookie
    By ecerrillos in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Oct 29, 2010, 7:05 PM
  5. Replies: 1
    Last Post: Sep 29, 2010, 3:10 PM

Posting Permissions