This is a migrated thread and some comments may be shown as answers.

RadDataGrid detect column click

1 Answer 91 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mark
Top achievements
Rank 1
Mark asked on 09 May 2019, 03:30 PM

Hi,

I have some rather special display requirements on data in my RadDataGrid.  While I'd love to let RadDataGrid handle the sorting I think I need to populate the grid in the order I'd like.

My question is can I detect via an event or something when a user changes the sort and direction on a particular column?  If so... how?

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 13 May 2019, 12:47 PM
Hello Mark,

You could detect whether a column sort action is executed through the ColumnHeaderTap Command of the DataGrid. You could create a custom ColumnHeaderTap command as described here: https://docs.telerik.com/devtools/universal-windows-platform/controls/raddatagrid/features/commands/datagrid-columnheadertapcommand.

In addition, in the Execute method you could access the Column and its SortDirection. Check below a quick example:

public class CustomColumnHeaderTapCommand : DataGridCommand
{
    public CustomColumnHeaderTapCommand()
    {
        this.Id = CommandId.ColumnHeaderTap;
    }
 
    public override bool CanExecute(object parameter)
    {
        var context = parameter as ColumnHeaderTapContext;
        // put your custom logic here
        return true;
    }
 
    public override void Execute(object parameter)
    {
        var context = parameter as ColumnHeaderTapContext;
        var sortDirection = context.Column.SortDirection;
        this.Owner.CommandService.ExecuteDefaultCommand(CommandId.ColumnHeaderTap, context);
        // put your custom logic here              
    }
}

I hope this would be of help.
 
Regards,
Yana
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DataGrid
Asked by
Mark
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or