Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
585
Get visible columns from previously saved DisplayLayout / keep applying layout while changing data source
posted

I'm trying to optimize code that displays a grid from a database query. Right now (vastly simplified), we:

  1. do a SELECT TOP 0 * from the database view and set that as the data source for the grid. That way, we know what columns potentially exist.
  2. if any, apply a user's previously saved display layout. Now, only their selected columns are visible (and groupby, filter, sort, etc. are applied).
  3. take the visible columns, and pass them on to do the actual query.
  4. "fill" the invisible remainder of the grid with NULL values

This works, vastly reduces the data transmitted, and helps the grid understand that these are "compatible" layouts. But it is in practice quite inefficient (for example, filtering can noticeably lag). What I'd prefer is for the grid to internally work with columns that actually exist; i.e. to skip step 4.

What I'd like to move towards is something like:

  1. figure out which columns potentially exist
  2. if any, fetch the user's previously saved display layout. We can't apply this yet because the grid doesn't have a data source (unless there's a way to get the grid to accept a display layout while not really having any data source?). But we can inspect which columns are visible. It seems I could simply do new UltraGridDisplayLayout(), then LoadFromXml(), and finally look at its properties.
  3. take those visible columns from the layout, and pass them on to do the actual query.
  4. set the grid data source, based on the actual query.
  5. actually apply the layout. However, this seems to require loading it twice. There is no setter for DisplayLayout.

I don't really mind step 5, but it seems a little inefficient. I could also simplify step 2, perhaps by specifying PropertyCategories.Bands.

But the bigger issue I run into right now is that the grid "forgets" some of the display layout along the way (such as sorted columns and groupby columns). Is there a way to "merge" the current grid's state to a new data source?

Is there something much easier that I'm missing to accomplish this? :)

Parents
  • 585
    Offline posted
    Sören Kuklau said:
    But the bigger issue I run into right now is that the grid "forgets" some of the display layout along the way (such as sorted columns and groupby columns). Is there a way to "merge" the current grid's state to a new data source?

    Huh, never mind that part. It was the fact that we were disposing the old data source that caused the display layout to be reset. If I simply save the layout to a byte[], then load it again from the same byte[] after the data source has been exchanged, the settings do get preserved (even if the new data source has additional columns).

    Still: are there more efficient/nicer ways of doing these?

    • Getting a layout's columns, so I know what data to fetch. Right now, I do something the following. Works, but seems a bit awkward.

                displayLayout.LoadFromXml(ms, PropertyCategories.Bands);
    
                return displayLayout.Bands[0].Columns
                                    .OfType<UltraGridColumn>()
                                    .Where(c => !c.Hidden || c.IsGroupByColumn)
                                    .Select(c => c.Key.ToLower())
                                    .ToList();
    

    • Re-applying the layout after the old data source has been disposed and replaced with a new one. In this case, we have a DataTable, and that seems to cause the grid to delete its layout altogether rather than wait for a new source.
Reply Children