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

Quicklist to users for grouping and sorting

3 Answers 76 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Inger Marie
Top achievements
Rank 1
Inger Marie asked on 06 Feb 2017, 02:39 PM

I have a radgridview with a bunch of columns. Each column has defined how to group and sort.

For instance:

  • The data: MeetingDate is a of a custom type, which has a Tostring()-override that returns the datetime as date only (and implements IComparable<T>, IEquatable<T>
  • GroupHeaderTemplate: Writes the date if there is one. Writes "None" otherwise
<telerik:GridViewDataColumn x:Name="_meetingDateColumn" IsReadOnly="True"
                                Header="Meeting date"
                                DataMemberBinding="{Binding MeetingDate.TheDateTime, UpdateSourceTrigger=PropertyChanged}"
                                GroupHeaderTemplate="{StaticResource GridDateColumnGroupHeaderTemplate}"
                               Width="SizeToCells"
                                GroupMemberPath="MeetingDate">
                                <telerik:GridViewDataColumn.HeaderCellStyle>
                                    <Style TargetType="telerik:GridViewHeaderCell">
                                        <Setter Property="ToolTipService.ToolTip" Value="Date when meeting is taking place"/>
                                        <Setter Property="ToolTipService.ShowDuration" Value="{x:Static Member=system:Int32.MaxValue}" />
                                    </Style>
                                </telerik:GridViewDataColumn.HeaderCellStyle>
  
                                <telerik:GridViewDataColumn.CellTemplate>
                                    <DataTemplate >
                                        <TextBlock VerticalAlignment="Top"
                                                Text="{Binding MeetingDate.TheDateTime, StringFormat={}{0:g}}"
                                                ToolTipService.Placement="Center" />
                                    </DataTemplate>
                                </telerik:GridViewDataColumn.CellTemplate>
                            </telerik:GridViewDataColumn>


I have around 20 columns, some are dates like the one above. One is industry, which groups by the category (http://ec.europa.eu/competition/mergers/cases/index/nace_all.html) but the column sorts by the entire industry name. Others are completely different - most have special handling of grouping and sorting.

The user is supposed to play around with grouping and sorting to find interesting stuff. However  - in addition - I would like to provide a few preset options, which the user should be able to choose in a drop down and have the grid re-arrange itself accordingly.

I would hate to implement all 20 grouping and sorting again - is there any way I can reuse the defination of sort and group from the columns in the gridview - and apply them to the radgridview group panel programatically ?

 

Thanks,

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 09 Feb 2017, 11:42 AM
Hello Inger Marie,

If I am understanding your enquiry correctly, you should be able to benefit from the programmatic sorting and grouping that RadGridView supports. The logic of these operations might be executed based on the selection of a RadComboBox, for example.

Would such an approach suit your needs or I am missing something?

Regards,
Stefan X1
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Inger Marie
Top achievements
Rank 1
answered on 09 Feb 2017, 12:12 PM

Yes - this is also what I have found out. I created a custom class which contains a list affected columns together with their wanted settings (for instance IsGrouped (boolean).

This seems to work - I have even added a filter for determining if any of the resulting groups should be expanded or not.

When the user selects an instance of this custom class in a combobox, the codebehind will run through the list of columns and do stuff based on the properties. Like this:

if (IsGrouped)
{
      ColumnSortDescriptor sortDescriptor = new ColumnSortDescriptor
       {
            Column = filter.Column,
            SortDirection = filter.ColumnSortDirection.Value
       };
        _theGridView.SortDescriptors.Add(sortDescriptor);
}

 

When ever the user selects "No filter" in the combobox - or prior to selecting another setting, I will call :

_theGridView.CollapseAllGroups();
 _theGridView.FilterDescriptors.SuspendNotifications();
foreach (GridViewColumn column in _theGridView.Columns)
    column.ClearFilters();
_theGridView.FilterDescriptors.ResumeNotifications();
 
_theGridView.GroupDescriptors.Clear();
_theGridView.SortDescriptors.Clear();

 

This seem to work within the boundaries of my specific needs.

0
Stefan
Telerik team
answered on 10 Feb 2017, 02:44 PM
Hello Inger Marie,

 I am happy that you've found a solution that meets your requirements.

In case you need any other assistance with our components, do not hesitate to contact us again.

All the best,
Stefan X1
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Inger Marie
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Inger Marie
Top achievements
Rank 1
Share this question
or