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

No rows displayed when filtering, grouping or sorting

7 Answers 266 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yefan
Top achievements
Rank 1
Veteran
Yefan asked on 18 Aug 2020, 10:37 AM

Hello,

I don't get any rows displayed when filtering with popup mode, grouping with drag&drop and sorting either by clicking on the column header or programatically.

And I get all my rows back when clearing filter/grouping/sorting either directly on the UI or programatically. Could you please help me?

 

Designer.xaml

<telerik:RadGridView x:Name="AttributesTable" ItemsSource="{Binding Path=Items}" RowDetailsVisibilityMode="Collapsed"
                             ScrollViewer.CanContentScroll="False" AutoGenerateColumns="False" CanUserSortColumns="True"
                             Sorting="AttributesTable_Sorting" PreparedCellForEdit="AttributesTable_PreparedCellForEdit"
                             CellEditEnded="AttributesTable_CellEditEnded"
                             FilteringMode="Popup" IsFilteringAllowed="True" MouseLeftButtonDown="AttributesTable_MouseLeftButtonDown"
                             FieldFilterEditorCreated="OnRadGridViewFieldFilterEditorCreated">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <Button Style="{StaticResource NoChromeButton}" Command="{base:XamlRoot Path=DataContext.Navigate}" CommandParameter="{Binding}">
                                <Image Source="/STTAR;component/Resources/Object_Globe_16xLG.png" ToolTip="{base:ResX ResKey=CenterMapToolTip}"/>
                            </Button>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

 

Code.cs

columns = (this.DataContext as AttributesTableViewModel)?.Columns;
items = (this.DataContext as AttributesTableViewModel)?.Items;
DynAdapter = (this.DataContext as AttributesTableViewModel)?.DynAdapter;

if (columns.Count == 0)
{
    var temp = AttributesTable.Columns[0];
    AttributesTable.Columns.Clear();
    AttributesTable.Columns.Add(temp);
    return;
}
 
var alreadyInsertedColsNames = (from col in (AttributesTable.Columns as ObservableCollection<GridViewColumn>).Where(col => col.DisplayIndex != 0) select col.Header as string).ToList();
var colsNames = (from col in columns select col.DisplayName).ToList();
var notInsertedColsNames = colsNames.Except(alreadyInsertedColsNames).ToList();
var toRemoveColsNames = alreadyInsertedColsNames.Except(colsNames).ToList();
 
if (notInsertedColsNames.Count > 0)
    foreach (string colName in notInsertedColsNames)
    {
        FeatureAttribute selectedCol = columns.Where(col => col.DisplayName == colName).FirstOrDefault();
        var gridViewColumn = new GridViewDataColumn();
 
        switch (selectedCol.Name)
        {
            case FeatureAttributes.Cost:
                string costUnit = String.Format(" ({0})", DynAdapter.Project.Settings.CurrencyCode);
                gridViewColumn.Header = selectedCol.DisplayName + costUnit;
                break;
            case FeatureAttributes.Length:
                string lengthUnit = " (m)";
                gridViewColumn.Header = selectedCol.DisplayName + lengthUnit;
                break;
            case FeatureAttributes.Id:
            case FeatureAttributes.Source:
            case FeatureAttributes.Support:
                gridViewColumn.IsReadOnly = true;
                gridViewColumn.Header = selectedCol.DisplayName;
                break;
            default:
                gridViewColumn.Header = selectedCol.DisplayName;
                break;
        }
 

                       // GetBindingStringForAttribute returns ".[propertyName]"

        gridViewColumn.DataMemberBinding = new Binding(GetBindingStringForAttribute(selectedCol));
        gridViewColumn.FilterMemberPath = GetBindingStringForAttribute(selectedCol);
        gridViewColumn.FilterMemberType = selectedCol.DataType;
        gridViewColumn.DataType = selectedCol.DataType;
        gridViewColumn.ShowDistinctFilters = false;
        gridViewColumn.CellTemplateSelector = (DataTemplateSelector)GridContainer.Resources["CellTemplateSelector"];
        gridViewColumn.CellEditTemplateSelector = (DataTemplateSelector)GridContainer.Resources["CellEditTemplateSelector"];
        AttributesTable.Columns.Add(gridViewColumn);
    }
 
    foreach (string toRem in toRemoveColsNames)
    {
        var colToRemove = (AttributesTable.Columns as ObservableCollection<GridViewColumn>)
        .FirstOrDefault(col => col.Header == toRem);
        if (AttributesTable.Columns.Contains(colToRemove))
            AttributesTable.Columns.Remove(colToRemove);
    }

7 Answers, 1 is accepted

Sort by
0
Yefan
Top achievements
Rank 1
Veteran
answered on 18 Aug 2020, 05:47 PM

I manage somehow to sort a specific column (see code below). However, I'd like multiple sort columns.

Hold Shift key + select another column header do nothing but sorting the other column and the previous selected one goes back to normal. And when I try the other method with sort descriptors, no rows are displayed in the grid.

 

private void AttributesTable_Sorting(object sender, GridViewSortingEventArgs e)
        {
            IEnumerable<DynamicFeatureToPropertyGridAdapter> items = e.DataControl.ItemsSource as IEnumerable<DynamicFeatureToPropertyGridAdapter>;
 
            if (items == null)
            {
                e.Cancel = true;
                return;
            }
            else
            {
                if (e.OldSortingState == SortingState.None)
                {
                    e.NewSortingState = SortingState.Ascending;
                    items = items.OrderBy(item => item[ConvertDataColumnUniqueNameBackToAttributeName((e.Column as GridViewDataColumn).GetDataMemberName())]);
                }
                else if (e.OldSortingState == SortingState.Ascending)
                {
                    e.NewSortingState = SortingState.Descending;
                    items = items.OrderByDescending(item => item[ConvertDataColumnUniqueNameBackToAttributeName((e.Column as GridViewDataColumn).GetDataMemberName())]);
                }
                else
                {
                    e.NewSortingState = SortingState.None;
                    items = items.OrderBy(item => item[FeatureAttributes.Id]);
                }
 
                e.DataControl.ItemsSource = items.ToList();
                e.Cancel = true;
            }
        }

 

0
Vladimir Stoyanov
Telerik team
answered on 20 Aug 2020, 07:08 AM

Hello Yefan,

Thank you for the shared code snippets. 

Generally speaking, setting the FilterMemberPath is necessary only when the column should be filtered on a property different than the one that it is datamemberbound to. That said, I am uncertain as to why the rows dissapear on your end after applying a data operation (filtering, sorting, grouping). 

I tested the scenario of dynamically adding columns, however I was not able to reproduce the same behavior. That is why I am attaching the sample project that I used for testing purposes. Can you check it out and see how it differs from the setup on your end? Should you need any further assistance, can you modify the sample project in order to demonstrate your scenario and send it over in a new support ticket (since project files cannot be attached to forum posts)? This will allow us to investigate the exact scenario and better assist you.

Thank you in advance for any help you can provide.

Regards,
Vladimir Stoyanov
Progress Telerik

0
Yefan
Top achievements
Rank 1
Veteran
answered on 20 Aug 2020, 08:02 AM

Thanks for the reply.

I tried your sample project, it does not seem it works. Please check the attached file.

0
Yefan
Top achievements
Rank 1
Veteran
answered on 20 Aug 2020, 08:11 AM

Oh nevermind, I did not see the button on the footer of the windows.

It seems like sorting and grouping work on this sample.

I'll try to think a little more and find out what causes the problem on my project and come back to you.

0
Vladimir Stoyanov
Telerik team
answered on 24 Aug 2020, 09:43 AM

Hello Yefan,

Feel free to take your time in investigating the project. 

Should you manage to discover more information that would help in replicating the scenario, do get back to us. 

Regards,
Vladimir Stoyanov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

0
Yefan
Top achievements
Rank 1
Veteran
answered on 10 Sep 2020, 01:36 PM

It seems like I found the issue. Data operations do not work when I do the binding with indexer.

Do you have any suggestion how I could do this, because I'd like avoid performance issues when binding with property name?

0
Vladimir Stoyanov
Telerik team
answered on 15 Sep 2020, 08:56 AM

Hello Yefan,

Please, allow me to start by saying that there shouldn't be any performance issues when setting the DataMemberBinding to a property name.

That said, I am not sure how the data is structured on your end and how the RadGridView is setup and it is difficult to suggest a concrete approach for your scenario. You can try setting the DataType property of the columns to see, if that helps. You can also check out the SortMemberPath/FilterMemberPath properties of the column.

If the above information proves unhelpful, can you share some sample code demonstrating how the data is setup and the definition of the RadGridView? You can also send over a sample project demonstrating the scenario in a new support ticket(since project files cannot be attached to forum posts).

Regards,
Vladimir Stoyanov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tags
GridView
Asked by
Yefan
Top achievements
Rank 1
Veteran
Answers by
Yefan
Top achievements
Rank 1
Veteran
Vladimir Stoyanov
Telerik team
Share this question
or