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

GroupDescriptor changed MVVM method?

1 Answer 22 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Jasper
Top achievements
Rank 1
Jasper asked on 17 May 2016, 07:16 PM

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();
    }
}

 

1 Answer, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 20 May 2016, 09:04 AM
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
Tags
DataGrid
Asked by
Jasper
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Share this question
or