WebGrid 7 - Updating Structure Dynamically Works...Almost

6 replies. Last post: June 3, 2011 7:09 AM by Handy Surya
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
A YousifMember

Our custom grid is completely database driven including the formatting.  So we do the custom structure work ourselves.  We also provide transparent "memory" of the grid as users modify it so it stores the grid structure any time a user modifies it, i.e., groups columns, sorts, resizes, removes or adds columns.

We store the info in XML via the grid's SaveTablesStructureToXml into our database and restore it and load it via LoadTablesStructureFromXml.

When we configure the grid, it's based on the grid definition provided by the database.  All the columns are created/updated depending on the grid definition provided.

The problem is to keep what's saved in sync with a changed definition structure.  This won't happen all that often, but when it does, we want to update the grid transparently without the user having to reload the page.

It's working, mostly, but I'm not sure what I'm missing and am hoping someone can help.  The attached CustomGridInitialLoad image shows the grid when initially loaded.  I then added a new column to the configuration in the database.  The CustomGridAfterRefreshGridData image shows the grid after I click on "Refresh grid data" which shows the column added in the data rows, but it's missing from the column headers.

If I reload the page (see CustomGridAfterPageRefresh image) everything loads just fine.  Essentially what I do in my CompareColumnConfiguration method is to:

  • Iterate through our grid definition structure
  • check if a column already exists in the current grid Columns collection
  • if it doesn't, then add it and format it
  • Now iterate through the grid's Columns collection
  • check if the column exists in our grid definition structure
  • if it doesn't, remove it, e.g., this.Columns.Remove(wgc)

When a column is removed from our definition structure and I refresh the grid via the refresh button or sorting or any action that posts the grid data, then it updates like image CustomGridColDelAfterRefreshGridData which shows the rows for the column are gone, but the header is still there.  If I refresh the entire page, it loads fine.

The column still there introduces other problems of course since it'll crash the grid if you try to sort on it or anything related to it since it no longer exists.

 

All times are GMT -5. The time now is 7:16 AM.
Previous Next