GroupDescriptor changed MVVM method?

2 posts, 0 answers
  1. Jasper
    Jasper avatar
    8 posts
    Member since:
    Dec 2015

    Posted 17 May Link to this post

    Hi there

    Is there an MVVM-pattern solution to trigger a ViewModel refresh (from an rpc-database backend) when the groupdescriptors of a DataGird are changed?

    Right now I've solved this issue with a C# event as below, but I'd like to have either the groupdescriptors bound to the viewmodel or I'd like to use an ICommand following MVVM principles.

    Current solution:

    dataGrid.GroupDescriptors.CollectionChanged += GroupDescriptors_CollectionChanged;
     
    private void GroupDescriptors_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        string groups = "";
        foreach (Telerik.Data.Core.PropertyGroupDescriptor gridGroup in dataGrid.GroupDescriptors)
        {
            groups += (String.IsNullOrWhiteSpace(groups) ? "" : ",") +
                ((gridGroup.SortOrder == Telerik.Data.Core.SortOrder.Ascending) ? "+" : "-") +
                 gridGroup.PropertyName;
        }
        This.ViewModel.GroupStringForRpcCall = groups;
    }

     

    Desired solution following MVVM principles:

    <gridCommands:DataGridUserCommand Id="ColumnHeaderTap" EnableDefaultCommand="True" Command="{Binding TelerikColumnHeaderSortCommand, Source={StaticResource ViewModel}}" />

    internal class TelerikRpcSortCommand : ICommand
    {
        private IRpcViewModel ViewModel;
     
        public TelerikRpcSortCommand(IRpcViewModel viewModel)
        {
            ViewModel = viewModel;
        }
     
        public event EventHandler CanExecuteChanged;
     
        public bool CanExecute(object parameter)
        {
            var context = parameter as ColumnHeaderTapContext;
            return true;
        }
     
        public async void Execute(object parameter)
        {
            var context = parameter as ColumnHeaderTapContext;
            var column = context.Column as DataGridTypedColumn;         
            string order = null;
     
            if (column.SortDirection == SortDirection.Ascending)
                order = "+" +column.PropertyName;
            else if (column.SortDirection == SortDirection.Descending)
                order = "-" + column.PropertyName;
            else
                order = "";
     
            ViewModel.Order = order;
            ViewModel.LoadDataAsync();
        }
    }

     

  2. Ivaylo Gergov
    Admin
    Ivaylo Gergov avatar
    661 posts

    Posted 20 May Link to this post

    Hi Jasper,

    Thank you for your interest.

    Currently, RadDataGrid does not expose a command for the grouping action so such approach could not be possible. Here are all the supported commands. I will log this as a feature request.

    Please, let me know should you need further assistance.
    Regards,
    Ivaylo Gergov
    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
  3. DevCraft banner
Back to Top