MAUI SfDataGrid MappingName not working with base class properties



We are facing an issue where MappingName is not working with base class properties. As the column sorting works based on the MappingName, some of the columns are not sorting which MappingName is assigned with a base class property. But data binding is working for these properties.


For example:

We have an interface InterfaceA which inherits InterfaceB. InterfaceB has an integer property called TestProperty. We are binding an observable collection of InterfaceA as the itemsource of the datagrid. 


<syncfusion:DataGridTemplateColumn MappingName="TestProperty">
    <syncfusion:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Label Text="{Binding TestProperty}"/>
        </DataTemplate>
    </syncfusion:DataGridTemplateColumn.CellTemplate>
</syncfusion:DataGridTemplateColumn>

Here, the datagrid is showing the values on this column but sorting is not applying. When we introduce the same property of the base interface in the inherited interface, then the sorting is working. Can we achieve this without hiding the base class property?


We have also tried custom sorting. In that case, the PropertyName is not accessible from the CustomSortComparer class.


Could you please share any work around for applying the sorting on base class properties?




1 Reply

SD Sethupathy Devarajan Syncfusion Team November 13, 2024 11:54 AM UTC

Hi Mohammed Fahmidur Rahman,

 

Please note that data bindings will work in this case, but data operations like sorting will not function as expected. This is because, in our source code, data operations are based on properties defined in the model class of the observable collection. In your scenario, the observable collection uses `Interface A` as its type, which does not include the `TestProperty`. As a result, the DataGrid cannot locate this property within `Interface A` and, therefore, cannot retrieve property values for sorting.

 

If you replace the observable collection’s type with `SampleData`, sorting will work, as all necessary properties are available within the `SampleData` class. We have shared a sample with this change for your reference.

 

Could you let us know if there is a specific reason for using `Interface A` as the collection type instead of `SampleData`? If so, please provide additional details, and we will be happy to analyze your requirements further and suggest an alternative solution.

 

Regards,

Sethupathy D.


Attachment: SfDataGridSample_fddd743e.zip

Loader.
Up arrow icon