RadDataGrid detect column click

2 posts, 0 answers
  1. Mark
    Mark avatar
    1 posts
    Member since:
    May 2019

    Posted 09 May Link to this post

    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?

  2. Yana
    Admin
    Yana avatar
    4916 posts

    Posted 13 May Link to this post

    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
Back to Top