Query 1:
How can I get sorted and/or grouped items from SfDataGrid after user's sorting? |
You can able to get the records of the group by passing the appropriate index to DisplayElements of View.TopLevelGroup as like the below code snippet,
Code Snippet:
| |
Query 2:
Can I get items from grid in it's current visible order?
|
You can achieve your requirement by using View.Records property as like below code,
Code Snippet:
|
Hello,
what I'm trying to achive is to have two grids and after sorting first, i want to generate items in second. I try this aproach and event SortColumnsChanged. But if I use var visibleOrder = this.DataGrid1.View.Records.ToList() it does not return correct order, more likely i get "old sorting", not actual.
example .. i got grid with two rows, Values 1 and 2. I click sort. In event i get order 1 - 2. But in view I see 2 - 1. It looks like I was using SortColumnsChanging, becouse as i said, in this.DataGrid1.View.Records.ToList() items are not sorted right in a time event is called .. can you fix this?
private void OnSortColumnsChanged(object sender, GridSortColumnsChangedEventArgs e)
{
//get the list
IEnumerable<object> OrderedSource = sfDataGrid.View.Records.Select(x => x.Data).AsEnumerable();
foreach (var sortColumn in this.sfDataGrid.View.SortDescriptions)
{
var columnName = sortColumn.PropertyName;
if (sortColumn.Direction == ListSortDirection.Ascending)
OrderedSource = OrderedSource.OrderBy(source => GetOrderSource(source, columnName));
else
OrderedSource = OrderedSource.OrderByDescending(source => GetOrderSource(source, columnName));
}
//assign to another DataGrid
sfDataGrid1.ItemsSource = OrderedSource;
}
private object GetOrderSource(object source, string name)
{
var propInfo = source.GetType().GetRuntimeProperty(name);
if (propInfo != null)
// get the current sort column value
return propInfo.GetValue(source);
return null;
} |