Can I define a datagrid column that is sorted in Silverlight?

I need to be able to load a results page into a grid of many tens of thousands of possible results. I want to retrieve data on pages from fifty from the server, using SQL Server to sort the data before returning them to bind to the datagrid. When the user sorts the dta into the datagrid by clicking on the column heading, I need to detect this and define a new order before returning to the database.

+3
source share
2 answers

I don't think there is a way to ask the datagrid which column is sorted. However, looking at http://blogs.msdn.com/scmorris/archive/2008/06/10/sorting-data-in-the-silverlight-datagrid.aspx , I see that you can implement your own sorting when implemented ICollectionView on its elements.

So, maybe you can implement the ICollectionView (wrapper around) of your results?

Datagrid does this internally if you set its ItemSource to IList, so maybe you can take a look at its implementation to see how they did it? (see inner class ListCollectionView Datagrids using reflector)

When you have an ICollectionView, you can use its SortDescriptions to find out the current sort.

Hope this helps you in the right direction?

Tjipke

0

PagedCollectionView SortDescriptions INotifyCollectionChanged. CollectionChanged. :

var collectionView = new PagedCollectionView(items);
(collectionView.SortDescriptions as INotifyCollectionChanged).CollectionChanged += (object sender, NotifyCollectionChangedEventArgs e) =>
{
  // This gets fired multiple times based on the previous sort and new sort
};
dataGrid.ItemsSource = collectionView;
0

Source: https://habr.com/ru/post/1703723/


All Articles