Skip to content

Commit 7a8dd6f

Browse files
Merge pull request #1 from SyncfusionExamples/Refresh_Sorting
MAUI- 959525 -Added KB sample to refresh Sorting dynamically when items source collection changed
2 parents e23f21e + 3e7e402 commit 7a8dd6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+9502
-2
lines changed

README.md

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,78 @@
1-
# How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid
2-
This demo shows how to refresh sorting dynamically when the items source collection changes in .NET MAUI DataGrid (SfDataGrid)?
1+
# How to refresh sorting dynamically when items source collection changes in .NET MAUI DataGrid SfDataGrid
2+
This demo shows how to refresh sorting dynamically when the items source collection changes in the Syncfusion [.NET MAUI DataGrid](https://help.syncfusion.com/maui/datagrid/overview) `SfDataGrid`. By using this sample we can apply the sorting to the updated DatGrid automatically.
3+
4+
## Xaml
5+
```
6+
<ContentPage.BindingContext>
7+
<local:OrderInfoRepository x:Name="viewModel" />
8+
</ContentPage.BindingContext>
9+
10+
<Grid RowDefinitions="50,*">
11+
<Button Text="ChangeCollection"
12+
Clicked="Button_Clicked" />
13+
14+
<syncfusion:SfDataGrid x:Name="dataGrid" Grid.Row="1" LiveDataUpdateMode="AllowDataShaping"
15+
ItemsSource="{Binding OrderInfoCollection}">
16+
<syncfusion:SfDataGrid.Columns>
17+
<syncfusion:DataGridTextColumn MappingName="OrderID"
18+
HeaderText="Order ID" />
19+
</syncfusion:SfDataGrid.Columns>
20+
<syncfusion:SfDataGrid.SortColumnDescriptions>
21+
<syncfusion:SortColumnDescription ColumnName="OrderID"
22+
SortDirection="Descending" />
23+
</syncfusion:SfDataGrid.SortColumnDescriptions>
24+
</syncfusion:SfDataGrid>
25+
</Grid>
26+
```
27+
28+
## Xaml.cs
29+
```
30+
public partial class MainPage : ContentPage
31+
{
32+
public MainPage()
33+
{
34+
InitializeComponent();
35+
}
36+
37+
private void Button_Clicked(object sender, EventArgs e)
38+
{
39+
viewModel.OrderInfoCollection.Clear();
40+
viewModel.ChangeCollection();
41+
}
42+
}
43+
```
44+
### OrderInfoRepository.cs
45+
```
46+
public void ChangeCollection()
47+
{
48+
orderInfo.Add(new OrderInfo("2001", "Selena Alvarad", "Sweden", "BERGS", "London"));
49+
orderInfo.Add(new OrderInfo("2002", "Sandra Altamirano", "Mexico", "ANATR", "Mexico D.F."));
50+
orderInfo.Add(new OrderInfo("2003", "Oscar Alpuerto", "France", "BLONP", "Strasbourg"));
51+
orderInfo.Add(new OrderInfo("2004", "Cecil Allison", "UK", "AROUT", "London"));
52+
orderInfo.Add(new OrderInfo("2005", "Tim Adams", "Germany", "ALFKI", "Berlin"));
53+
orderInfo.Add(new OrderInfo("2006", "Michael Allen", "Canada", "BOTTM", "Lenny Lin"));
54+
orderInfo.Add(new OrderInfo("2007", "Andrew Fuller", "France", "BLONP", "Strasbourg"));
55+
orderInfo.Add(new OrderInfo("2008", "Martin King", "Spain", "BOLID", "Madrid"));
56+
orderInfo.Add(new OrderInfo("2009", "Phyllis Allen", "France", "BONAP", "Marsiella"));
57+
orderInfo.Add(new OrderInfo("2010", "John Carter", "UK", "AROUT", "London"));
58+
orderInfo.Add(new OrderInfo("2011", "Marvin Allen", "Sweden", "BERGS", "London"));
59+
orderInfo.Add(new OrderInfo("2012", "Anne Wilson", "Germany", "BLAUS", "Mannheim"));
60+
orderInfo.Add(new OrderInfo("2013", "Sean Jacobson", "Mexico", "ANTON", "Mexico D.F."));
61+
orderInfo.Add(new OrderInfo("2014", "Gina Irene", "UK", "AROUT", "London"));
62+
}
63+
```
64+
65+
Executing the code example above yields the following output
66+
67+
<img src="https://github.com/user-attachments/assets/94730d54-b826-4831-bef3-ae2148a8489d" width=800/>
68+
69+
View sample in [GitHub](https://github.com/SyncfusionExamples/How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid/tree/Refresh_Sorting)
70+
71+
Take a moment to explore this [documentation](https://help.syncfusion.com/maui/datagrid/overview), where you can find more information about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this [link](https://www.syncfusion.com/maui-controls/maui-datagrid) to learn about the essential features of Syncfusion .NET MAUI DataGrid (SfDataGrid).
72+
73+
### Conclusion
74+
I hope you enjoyed learning about How to implement select all checkbox column in SfDataGrid.
75+
76+
You can refer to our [.NET MAUI DataGrid’s feature tour](https://www.syncfusion.com/maui-controls/maui-datagrid) page to learn about its other groundbreaking feature representations. You can also explore our [.NET MAUI DataGrid Documentation](https://help.syncfusion.com/maui/datagrid/getting-started) to understand how to present and manipulate data. For current customers, you can check out our .NET MAUI components on the [License and Downloads](https://www.syncfusion.com/sales/teamlicense) page. If you are new to Syncfusion, you can try our 30-day [free trial](https://www.syncfusion.com/downloads/maui) to explore our .NET MAUI DataGrid and other .NET MAUI components.
77+
78+
If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our [support forums](https://www.syncfusion.com/forums),[Direct-Trac](https://support.syncfusion.com/create) or [feedback portal](https://www.syncfusion.com/feedback/maui?control=sfdatagrid), or the feedback portal. We are always happy to assist you!
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"Version": 1,
3+
"WorkspaceRootPath": "D:\\GIT\\Refresh_Sorting\\How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid\\SfDataGridSample\\",
4+
"Documents": [
5+
{
6+
"AbsoluteMoniker": "D:0:0:{1C376DAF-3809-446B-996B-371DBB2A563A}|SfDataGridSample\\SfDataGridSample.csproj|d:\\git\\refresh_sorting\\how-to-refresh-sorting-when-items-source-collection-changes-in-.net-maui-datagrid-sfdatagrid\\sfdatagridsample\\sfdatagridsample\\mainpage.xaml||{F11ACC28-31D1-4C80-A34B-F4E09D3D753C}",
7+
"RelativeMoniker": "D:0:0:{1C376DAF-3809-446B-996B-371DBB2A563A}|SfDataGridSample\\SfDataGridSample.csproj|solutionrelative:sfdatagridsample\\mainpage.xaml||{F11ACC28-31D1-4C80-A34B-F4E09D3D753C}"
8+
},
9+
{
10+
"AbsoluteMoniker": "D:0:0:{1C376DAF-3809-446B-996B-371DBB2A563A}|SfDataGridSample\\SfDataGridSample.csproj|d:\\git\\refresh_sorting\\how-to-refresh-sorting-when-items-source-collection-changes-in-.net-maui-datagrid-sfdatagrid\\sfdatagridsample\\sfdatagridsample\\sfdatagridsample.csproj||{FA3CD31E-987B-443A-9B81-186104E8DAC1}|",
11+
"RelativeMoniker": "D:0:0:{1C376DAF-3809-446B-996B-371DBB2A563A}|SfDataGridSample\\SfDataGridSample.csproj|solutionrelative:sfdatagridsample\\sfdatagridsample.csproj||{FA3CD31E-987B-443A-9B81-186104E8DAC1}|"
12+
},
13+
{
14+
"AbsoluteMoniker": "D:0:0:{1C376DAF-3809-446B-996B-371DBB2A563A}|SfDataGridSample\\SfDataGridSample.csproj|d:\\git\\refresh_sorting\\how-to-refresh-sorting-when-items-source-collection-changes-in-.net-maui-datagrid-sfdatagrid\\sfdatagridsample\\sfdatagridsample\\viewmodel\\orderinforepository.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
15+
"RelativeMoniker": "D:0:0:{1C376DAF-3809-446B-996B-371DBB2A563A}|SfDataGridSample\\SfDataGridSample.csproj|solutionrelative:sfdatagridsample\\viewmodel\\orderinforepository.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
16+
},
17+
{
18+
"AbsoluteMoniker": "D:0:0:{1C376DAF-3809-446B-996B-371DBB2A563A}|SfDataGridSample\\SfDataGridSample.csproj|d:\\git\\refresh_sorting\\how-to-refresh-sorting-when-items-source-collection-changes-in-.net-maui-datagrid-sfdatagrid\\sfdatagridsample\\sfdatagridsample\\model\\orderinfo.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
19+
"RelativeMoniker": "D:0:0:{1C376DAF-3809-446B-996B-371DBB2A563A}|SfDataGridSample\\SfDataGridSample.csproj|solutionrelative:sfdatagridsample\\model\\orderinfo.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
20+
},
21+
{
22+
"AbsoluteMoniker": "D:0:0:{1C376DAF-3809-446B-996B-371DBB2A563A}|SfDataGridSample\\SfDataGridSample.csproj|d:\\git\\refresh_sorting\\how-to-refresh-sorting-when-items-source-collection-changes-in-.net-maui-datagrid-sfdatagrid\\sfdatagridsample\\sfdatagridsample\\mainpage.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
23+
"RelativeMoniker": "D:0:0:{1C376DAF-3809-446B-996B-371DBB2A563A}|SfDataGridSample\\SfDataGridSample.csproj|solutionrelative:sfdatagridsample\\mainpage.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
24+
}
25+
],
26+
"DocumentGroupContainers": [
27+
{
28+
"Orientation": 0,
29+
"VerticalTabListWidth": 256,
30+
"DocumentGroups": [
31+
{
32+
"DockedWidth": 200,
33+
"SelectedChildIndex": 7,
34+
"Children": [
35+
{
36+
"$type": "Bookmark",
37+
"Name": "ST:0:0:{34e76e81-ee4a-11d0-ae2e-00a0c90fffc3}"
38+
},
39+
{
40+
"$type": "Bookmark",
41+
"Name": "ST:128:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
42+
},
43+
{
44+
"$type": "Bookmark",
45+
"Name": "ST:129:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
46+
},
47+
{
48+
"$type": "Bookmark",
49+
"Name": "ST:130:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
50+
},
51+
{
52+
"$type": "Bookmark",
53+
"Name": "ST:128:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
54+
},
55+
{
56+
"$type": "Document",
57+
"DocumentIndex": 1,
58+
"Title": "SfDataGridSample.csproj",
59+
"DocumentMoniker": "D:\\GIT\\Refresh_Sorting\\How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid\\SfDataGridSample\\SfDataGridSample\\SfDataGridSample.csproj",
60+
"RelativeDocumentMoniker": "SfDataGridSample\\SfDataGridSample.csproj",
61+
"ToolTip": "D:\\GIT\\Refresh_Sorting\\How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid\\SfDataGridSample\\SfDataGridSample\\SfDataGridSample.csproj",
62+
"RelativeToolTip": "SfDataGridSample\\SfDataGridSample.csproj",
63+
"ViewState": "AgIAADAAAAAAAAAAAAAAAEIAAAAAAAAAAAAAAA==",
64+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000758|",
65+
"WhenOpened": "2025-05-28T11:52:40.037Z",
66+
"EditorCaption": ""
67+
},
68+
{
69+
"$type": "Document",
70+
"DocumentIndex": 4,
71+
"Title": "MainPage.xaml.cs",
72+
"DocumentMoniker": "D:\\GIT\\Refresh_Sorting\\How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid\\SfDataGridSample\\SfDataGridSample\\MainPage.xaml.cs",
73+
"RelativeDocumentMoniker": "SfDataGridSample\\MainPage.xaml.cs",
74+
"ToolTip": "D:\\GIT\\Refresh_Sorting\\How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid\\SfDataGridSample\\SfDataGridSample\\MainPage.xaml.cs",
75+
"RelativeToolTip": "SfDataGridSample\\MainPage.xaml.cs",
76+
"ViewState": "AgIAAAUAAAAAAAAAAAAAwA4AAAAiAAAAAAAAAA==",
77+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
78+
"WhenOpened": "2025-05-28T11:20:06.45Z"
79+
},
80+
{
81+
"$type": "Document",
82+
"DocumentIndex": 0,
83+
"Title": "MainPage.xaml",
84+
"DocumentMoniker": "D:\\GIT\\Refresh_Sorting\\How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid\\SfDataGridSample\\SfDataGridSample\\MainPage.xaml",
85+
"RelativeDocumentMoniker": "SfDataGridSample\\MainPage.xaml",
86+
"ToolTip": "D:\\GIT\\Refresh_Sorting\\How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid\\SfDataGridSample\\SfDataGridSample\\MainPage.xaml",
87+
"RelativeToolTip": "SfDataGridSample\\MainPage.xaml",
88+
"ViewState": "AgIAAAkAAAAAAAAAAAAowA0AAAAoAAAAAAAAAA==",
89+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.003549|",
90+
"WhenOpened": "2025-05-28T11:18:26.71Z",
91+
"EditorCaption": ""
92+
},
93+
{
94+
"$type": "Document",
95+
"DocumentIndex": 2,
96+
"Title": "OrderInfoRepository.cs",
97+
"DocumentMoniker": "D:\\GIT\\Refresh_Sorting\\How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid\\SfDataGridSample\\SfDataGridSample\\ViewModel\\OrderInfoRepository.cs",
98+
"RelativeDocumentMoniker": "SfDataGridSample\\ViewModel\\OrderInfoRepository.cs",
99+
"ToolTip": "D:\\GIT\\Refresh_Sorting\\How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid\\SfDataGridSample\\SfDataGridSample\\ViewModel\\OrderInfoRepository.cs",
100+
"RelativeToolTip": "SfDataGridSample\\ViewModel\\OrderInfoRepository.cs",
101+
"ViewState": "AgIAAAsAAAAAAAAAAAAAwDUAAABZAAAAAAAAAA==",
102+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
103+
"WhenOpened": "2025-05-28T11:17:27.295Z"
104+
},
105+
{
106+
"$type": "Document",
107+
"DocumentIndex": 3,
108+
"Title": "OrderInfo.cs",
109+
"DocumentMoniker": "D:\\GIT\\Refresh_Sorting\\How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid\\SfDataGridSample\\SfDataGridSample\\Model\\OrderInfo.cs",
110+
"RelativeDocumentMoniker": "SfDataGridSample\\Model\\OrderInfo.cs",
111+
"ToolTip": "D:\\GIT\\Refresh_Sorting\\How-to-refresh-sorting-when-items-source-collection-changes-in-.NET-MAUI-DataGrid-SfDataGrid\\SfDataGridSample\\SfDataGridSample\\Model\\OrderInfo.cs",
112+
"RelativeToolTip": "SfDataGridSample\\Model\\OrderInfo.cs",
113+
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAYAAAAaAAAAAAAAAA==",
114+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
115+
"WhenOpened": "2025-05-28T11:17:04.027Z"
116+
}
117+
]
118+
}
119+
]
120+
}
121+
]
122+
}

0 commit comments

Comments
 (0)