Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGrid setViewState

    Hi

    I want to restore a state of a Listgrid with setViewState. But when I use this method with the string obtained earlier with getViewState as a parameter, only he sorting of column appear, the order of the column is not the same and the hidden column are shown.

    Do anybody had this problem ?

    thank you

    #2
    Make sure the field names are the same.

    Comment


      #3
      Hi

      thanks for your quick reply.

      I double check and field are the same name.

      Comment


        #4
        If you can't figure it out, post a minimal standalone test case.

        Comment


          #5
          Hi

          Here's a quick example.

          Code:
           
          
          grid = new ListGrid();
          			
          grid.setWidth100();
          grid.setHeight(GRID_HEIGHT);
          grid.setPadding(5);
          grid.setAlternateRecordStyles(true);
          grid.setCanEdit(true);
          grid.setCanFreezeFields(true);
          
          grid.setSaveLocally(true);
          grid.setShowRollOver(true);
          grid.setEditEvent(ListGridEditEvent.CLICK);
          			
          grid.setAutoFetchData(true);
          			
          grid.setFields(createSecondaryInfos());
          grid.setDataSource(createSecondaryInfosDataSource(grid.getID()));
          
          try {					
          grid.setViewState(viewState);
          } catch (Exception e) {
          	e.printStackTrace();
          }
          The columns have the same name in the method setField and the variable viewState.

          thanks

          Comment


            #6
            A standalone test case is one that can be immediately run with no external dependencies. What you've posted is not useful as we already have automated tests verifying that this feature works. The most likely explanation bug in your code, but if it were possible to prepare a standalone, minimal test case there would be a reason to look into the problem as a possible bug.

            Comment


              #7
              Here, a case where I create a grid on which I made setViewState with a string obtained by getViewState. But setViewState seems to have no effect.

              I attach the class.

              Did I miss something ?
              Attached Files

              Comment


                #8
                Hi Orelia
                The stored viewState string
                Code:
                String state = "({    selected:\"[\\r]\",     field:\"[\\r    {\\r        name:\"countryName\", \\r        width:null\\r    }, \\r    {\\r        name:\"member_g8\", \\r        width:null\\r    }, \\r    {\\r        name:\"population\", \\r        width:null\\r    }, \\r    {\\r        name:\"continent\", \\r        visible:false, \\r        width:null\\r    }, \\r    {\\r        name:\"independence\", \\r        width:80\r    }\\r]\",    sort:\"({\\r    fieldName:null, \\r    sortDir:true\\r})\"})";
                Appears to be invalid. The string ends up being evaluated as javascript on the client but the escaping for various quotation marks is incorrect which would cause errors - when you run this code I'd expect to see an error in the developer console window saying something like "Unable to parse viewState".

                How did you initially get this string - presumably it was returned from a call to getViewState() at some point but was it directly copied / pasted from somewhere? Did you hand edit it at all?

                Thanks
                Isomorphic Software

                Comment


                  #9
                  I have seen so many post saying it's a wrong quoted string without showing a example of the valid quoted string. Isomorphic, could you please post a example of valid quoted string from ListGrid.getViewState(), which could be passed to the server and received from the server (using JSON) and successfully restore the ListGrid state.
                  Thanks

                  Comment


                    #10
                    You can see in the Grid Preferences sample.

                    Comment


                      #11
                      Thanks,
                      I am still getting parse error, I don't see anything wrong with the string, any Ideas?
                      Unable to parse viewState object passed in:

                      WARN:ListGrid:isc_ListGrid_0:Unable to parse viewState object passed in: ({selected:"[
                      ]",field:"[
                      {
                      name:"groupName",
                      visible:false,
                      width:null
                      },
                      {
                      name:"deviceName",
                      width:null
                      },
                      {
                      name:"tag",
                      width:null
                      },
                      {
                      name:"pointName",
                      width:null
                      },
                      {
                      name:"val",
                      width:null
                      },
                      {
                      name:"uom",
                      width:null
                      },
                      {
                      name:"dts",
                      width:120
                      }
                      ]",sort:"({
                      fieldName:"pointName",
                      sortDir:true,
                      sortSpecifiers:[
                      {
                      property:"pointName",
                      direction:"ascending"
                      }
                      ]
                      })"}) Ignoring.

                      Comment


                        #12
                        Don't think there should be quotes around the [] of selected and field and () of sort.

                        Comment


                          #13
                          If you can't figure it out, post a minimal standalone test case.











                          ____________________
                          Chúng tôi là một trong những công ty tu van du hoc hàng đầu Việt Nam .Chúng tôi là đại diện cho nhiều tập đoàn du hoc hàng đầu TG tại Vietnam .Hàng năm đều có các xuất hoc bong du hoc miễn phí đi vụ du hoc singapore.tu van du hoc voi lai hoc bong du hoc
                          | noi that fami|noi that 190|
                          Last edited by mrphantuan; 12 May 2011, 01:51.

                          Comment


                            #14
                            problem solved thanks!
                            If anybody interested, this is how I pass the state to the server
                            String pref = grid.getViewState();
                            pref = JsonUtils.escapeValue(pref);
                            I also remove first and last " from the string.

                            Comment

                            Working...
                            X