3 Replies Latest reply on Jun 24, 2011 10:03 AM by flexnewbie2011

    persisting datagrid columns order


      I am saving the order to the cookie using user.data.gridcolumns = grid.columns, and this works. But when I am trying to reset the order by doing
      grid.columns = user.data.gridcolumns, it throws an error saying that it cannot convert the object to datagridcolumn. any ideas?

        • 1. Re: persisting datagrid columns order
          flexnewbie2011 Level 1

          I think the problem lies with the object type. after saving the info, the trace shows that gridcolumns is "[object DataGridColumn]" which is correct. but when loading the info, the trace shows  that gridcolumns is "[object object]" which could be causing the error. did the object somehow get flattened? how to solve this? please help!

          • 2. Re: persisting datagrid columns order
            flexnewbie2011 Level 1

            after some research, it seems that I need to use flash.net.registerClassAlias()/registerClassAlias() to store/retreive typed objects. anyone knows how to use them?

            • 3. Re: persisting datagrid columns order
              flexnewbie2011 Level 1

              After trying various methods, I figrued oit a simpler approach which maybe useful to anyone who wishes to persist column order. The challenges
              were: 1. storing a typed object in the cookie 2. some columns use itemRenderer instead of dataField.


              This is what I did:


              1. on "headerShift", loop through the grid columns and store the headerText of all the columns in an array ARR
              2. assign ARR.toString() to user.data.ColumnHeaderText
              3. when the user logs in the next time, retrieve the cookie and do a split (',') on user.data.ColumnHeaderText and assign it to array ColumnHeaderTextArray
              4. create a new NewColumnsArray as the new grid columns array
              5. start a for loop based on the ColumnHeaderTextArray length, inside of that, start another for loop based on the grid columns length
              6. match the headerText of both array items: if (ColumnHeaderTextArray[i] == grid.columns[j].headerText)
              7. push the matched column to NewColumnsArray: NewColumnsArray.push(grid.columns[j])
              8. delete all the existing columns in the grid
              9. assign NewColumnsArray to the grid: grid.columns = NewColumnsArray
              10. refresh the grid: grid.invalidateDisplayList()


              This solution does not involve storing typed object in the cookie which is a nightmare. Also, it avoids dealing with itemRenderer which also is a typed object (IFactory).