Not able to get proper value of grid panel Column from getState methods.

  1. #1

    Not able to get proper value of grid panel Column from getState methods.

    In the grid panel have hide the column's. Suppose i have 5 column in the grid and hide the last column. For Example
    {
      "columns": [
        {
          "id": "ctl00_mainContentPlaceHolder_Priority"
        },
        {
          "id": "ctl00_mainContentPlaceHolder_EmployeeID"
        },
        {
          "id": "ctl00_mainContentPlaceHolder_EquipmentId"
        },
        {
          "id": "ctl00_mainContentPlaceHolder_Notes",
          "hidden": true
        },
      ]
    }
    i got this value by using the getState method. Now I hide the second last column i.e "EquipmentId" the then i got using getState methods value.
    {
      "columns": [
        {
          "id": "ctl00_mainContentPlaceHolder_Priority"
        },
        {
          "id": "ctl00_mainContentPlaceHolder_EmployeeID"
        },
        {
          "id": "ctl00_mainContentPlaceHolder_EquipmentId",
          "hidden": true
        },
        {
          "id": "ctl00_mainContentPlaceHolder_Notes"    
        },
      ]
    }
    As you can seen here the state of "Notes" is not coming, this column was hidden at first time . Due which Notes column become visible to the users.
    Please suggest me for the same.
    Last edited by fabricio.murta; Jan 22, 2016 at 9:12 PM. Reason: Wrap [code] tags around code.
  2. #2
    Hello!

    Please, wrap your code on [ code] tags when you paste code on threads. :)

    State is not supposed to track the initial state changes on columns, as they are set by the code behind or when the page is built (system defaults -- not user set).

    For example, if you un-hide your first column, you will get an explicit state of hidden: false, because you manually made the column to show. But if you do nothing, you haven't specified anything, so the state won't specify either. This way, if the user never changed the column's visibility and saved (in cookies for example) the state, and the page changes its defaults to show the column, it will be shown -- instead of keep hidden forever even after you change the default display.

    If you want to automatically add the state change to users when they load the page, one thing you can do is adding JavaScript code to hide/show the columns after the page is loaded.

    For example, from code behind:
    X.AddScript("App.MyGrid.columns[1].hide();");
    To hide the second column (in the order they are declared in the model). And this will apply to the state information. Assuming your grid has an ID after MyGrid

    If directly from JavaScript, just use the code inside quotes above:
    App.MyGrid.columns[1].hide();
    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3

    Hi fabricio.murta

    Thanks for the suggestion it work.

    But i run into same issue when my page get post-back again, when the user again change Column hide/show at time time not able to get the state hidden: false . Can you please help me on this.
  4. #4
    As you are forcing the user to set the default like that, I believe you have to fetch the getValue() result, check if that is set in the array, and only if not set, run the command to change the column.

    Something like:
    var curState = this.getState();
    
    if (curState.columns[1].hidden === 'undefined') {
        App.MyGrid.columns[1].hide();
    }
    i.e. only force-hide (and set user state) if the state is not already defined.

    Well, at least if I understood your question correctly, that is.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] GridPanel getState() gets only column ID
    By ViDom in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 10, 2013, 10:14 PM
  2. [CLOSED] Save ext:GridPanel.getState() in SQL Server database
    By supera in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 03, 2012, 11:17 AM
  3. Replies: 5
    Last Post: Dec 26, 2011, 5:39 AM
  4. Replies: 5
    Last Post: May 05, 2011, 7:05 PM
  5. Replies: 16
    Last Post: Feb 23, 2011, 10:03 AM

Posting Permissions