我的xaml代码中有一个数据网格。我在视图模型中通过处理排序列改变事件来应用排序。还有一个单独的组列描述字段。
当我用一列对网格进行排序时,无论我选择什么顺序,调试器都会显示正确的结果,但当它出现在屏幕上时,它又被分组的列排序了。
这是我的xaml代码。
xmlns:my="using:Syncfusion.UI.Xaml.Grid"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:i="using:Microsoft.Xaml.Interactivity"
<my:SfDataGrid
x:Name="ListReportForFilter"
Margin="20,20,20,0"
GroupCaptionTextFormat="Tracking Number: {Key}"
AutoExpandGroups="True"
ItemsSource="{Binding SearchReportPageFullList,Mode=TwoWay}"
Visibility="Visible"
AutoGenerateColumns="False"
BorderBrush="Transparent"
AllowFiltering="True"
AllowSorting="True"
ColumnSizer="Star"
SelectionMode="None">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="FilterChanged">
<core:InvokeCommandAction Command="{Binding FilterChangedOnGrid}" />
</core:EventTriggerBehavior>
<core:EventTriggerBehavior EventName="SortColumnsChanged">
<core:InvokeCommandAction Command="{Binding SortingChangedOnGrid}" />
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
<my:SfDataGrid.GroupColumnDescriptions>
<my:GroupColumnDescription ColumnName="TrackingNumber"/>
</my:SfDataGrid.GroupColumnDescriptions>
<my:SfDataGrid.Columns>
<my:GridTextColumn HeaderText="Recipient"
TextAlignment="Center"
MappingName="Recipient"
AllowBlankFilters="False"
/>
<my:GridTextColumn HeaderText="Function"
MappingName="Function"
AllowBlankFilters="False"
TextAlignment="Center"
/>
<my:GridTextColumn HeaderText="Carrier"
MappingName="Carrier"
AllowBlankFilters="False"
TextAlignment="Center"
/>
<my:GridTextColumn HeaderText="Tracking Number"
MappingName="TrackingNumber"
IsHidden="True"
TextAlignment="Center"
/>
<my:GridTextColumn HeaderText="Item Type"
MappingName="ItemType"
AllowBlankFilters="False"
TextAlignment="Center"
/>
<my:GridTextColumn HeaderText="Date"
MappingName="Date"
AllowBlankFilters="False"
TextAlignment="Center"
/>
<my:GridTextColumn HeaderText="Location"
MappingName="Location"
AllowBlankFilters="False"
TextAlignment="Center"
/>
<my:GridTextColumn HeaderText="Duration (hrs)"
MappingName="Duration"
AllowBlankFilters="False"
TextAlignment="Center"
/>
</my:SfDataGrid.Columns>
</my:SfDataGrid>
这是我的视图模型代码,其中有Sort Columns Changed事件。
public DelegateCommand<GridSortColumnsChangedEventArgs> SortingChangedOnGrid { get; }
SortingChangedOnGrid = new DelegateCommand<GridSortColumnsChangedEventArgs(SortingOnSFDataGridChanged);
private void SortingOnSFDataGridChanged(GridSortColumnsChangedEventArgs sortingdata)
{
try
{
var newSearchtotalFullList = new List<UndeliveredReportModel>();
var columnNameSelected = sortingdata.AddedItems.FirstOrDefault().ColumnName;
List<UndeliveredReportModel> totalDataAsPerFilterr = new List<UndeliveredReportModel>();
switch (columnNameSelected)
{
case "Recipient":
if (sortingdata.AddedItems.FirstOrDefault().SortDirection == Syncfusion.Data.ListSortDirection.Ascending)
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderBy(x => x.Recipient).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
else
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderByDescending(x => x.Recipient).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
case "Function":
if (sortingdata.AddedItems.FirstOrDefault().SortDirection == Syncfusion.Data.ListSortDirection.Ascending)
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderBy(x => x.Function).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
else
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderByDescending(x => x.Function).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
case "ItemType":
if (sortingdata.AddedItems.FirstOrDefault().SortDirection == Syncfusion.Data.ListSortDirection.Ascending)
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderBy(x => x.ItemType).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
else
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderByDescending(x => x.ItemType).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
case "Carrier":
if (sortingdata.AddedItems.FirstOrDefault().SortDirection == Syncfusion.Data.ListSortDirection.Ascending)
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderBy(x => x.Carrier).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
else
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderByDescending(x => x.Carrier).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
case "Date":
if (sortingdata.AddedItems.FirstOrDefault().SortDirection == Syncfusion.Data.ListSortDirection.Ascending)
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderBy(x => x.Date).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
else
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderByDescending(x => x.Date).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
case "Location":
if (sortingdata.AddedItems.FirstOrDefault().SortDirection == Syncfusion.Data.ListSortDirection.Ascending)
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderBy(x => x.Location).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
else
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderByDescending(x => x.Location).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
case "TrackingNumber":
if (sortingdata.AddedItems.FirstOrDefault().SortDirection == Syncfusion.Data.ListSortDirection.Ascending)
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderBy(x => x.TrackingNumber).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
else
{
totalDataAsPerFilterr = SearchReportPageFullList.OrderByDescending(x => x.TrackingNumber).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
case "Duration":
if (sortingdata.AddedItems.FirstOrDefault().SortDirection == Syncfusion.Data.ListSortDirection.Ascending)
{
//var asc = SearchReportPageFullList.OrderBy(x=>x.Duration).GroupBy(y => y.TrackingNumber).ToList();
totalDataAsPerFilterr = SearchReportPageFullList.OrderBy(x => x.Duration).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
else
{
//var asc = SearchReportPageFullList.OrderByDescending(x => x.Duration).GroupBy(y => y.TrackingNumber).OrderBy(x => x.Key).ToList();
totalDataAsPerFilterr = SearchReportPageFullList.OrderByDescending(x => x.Duration).ToList();
newSearchtotalFullList = newSearchtotalFullList.Concat(totalDataAsPerFilterr).ToList();
break;
}
}
SearchReportPageFullList = newSearchtotalFullList;
}
catch (Exception ex)
{
}
}
我正在使用Syncfusion UWP工具来实现这个功能,因为它符合我们的要求。
先谢谢你。
你的要求可以通过在SfDataGrid的GroupColumnDescriptions中设置SortGroupRecords值为False来实现。请参考下面的代码片段,供您参考。
<syncfusion:SfDataGrid.GroupColumnDescriptions>
<syncfusion:GroupColumnDescription ColumnName="OrderID" SortGroupRecords="False" />
</syncfusion:SfDataGrid.GroupColumnDescriptions>