I want to sort my datagrid using button

1 Answer 13 Views
DataGrid
Tamil
Top achievements
Rank 1
Tamil asked on 18 Jul 2021, 06:40 PM

I want to sort particular columns in my datagrid using button. I placed this button in another page. If I click that button means it want to go datagrid page and sort that particular columns in automatically its possible!??

I tried but it's not working 

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 19 Jul 2021, 04:12 PM

Hello Tamil,

You can programmatically sort a DataGrid at any time by simply adding a new SortDescriptor to the DataGrid.

For example, this code clears any current sorting and then adds a new sort for "FirstName".

// Clear any existing sorting
dataGrid.SortDescriptors.Clear();

// Sort the DataGrid by the "FirstName" property
dataGrid.sortDescriptors.Add(new PropertySortDescriptor { PropertyName = "FirstName" });

That means you can definitely use a Button click event handler or a Page OnNavigatedTo method to do that:

private void MyButton_OnClick(object sender, EventArgs args)
{
    dataGrid.SortDescriptors.Clear();
    dataGrid.sortDescriptors.Add(new PropertySortDescriptor { PropertyName = "FirstName" });
}

You can review the DataGrid documentation for more information UWP DataGrid Documentation | Overview | Telerik UI for Universal Windows Platform

Navigation Specifics

I don't know what you're referring to about navigation. Any app navigation you want to perform is outside of the responsibility of the DataGrid and any sorting operations.

If you just want to apply a sort when a page is first navigated to, then you just use the Page OnNavigatedTo method or Page Loaded event handler to do your programmatic sorting.

If you have any questions about navigation or passing parameters in your navigation, I recommend opening a post in the new Microsoft Q&A Forums or StackOverflow instead of here.

Regards,
Lance | Manager Technical Support
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
DataGrid
Asked by
Tamil
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or