Hello,
I am trying to implement a datagrid on the mobile app. here is my problem i have xaml code that is grouped by date variable in grouping mode. and i am trying to fetchdata as you see above i am directly creating a new observablecollection and assigning it to binded variable in this example Campaigns is the property that is binded to xaml
private async Task FetchChartDataAsync()
{
_isFetchingData = true;
await WebRequestExecuter.Execute(async () => await _camnpaignsAppService.GetSalesStats(_input), result =>
{
//Campaigns.Clear();
//Sales.Clear();
var campaigns = ObjectMapper.Map<List<CampaignSummaryModel>>(result.Campaigns);
var salesSummary = ObjectMapper.Map<List<SalesSummaryModel>>(result.Sales);
foreach (var campaign in campaigns)
{
campaign.DateType = _input.Type;
Campaigns.Add(campaign);
}
foreach (var sale in salesSummary)
{
sale.DateType = _input.Type;
Sales.Add(sale);
}
//OnPropertyChanged("Campaigns");
//OnPropertyChanged("Sales");
var campaignsObservable = new ObservableCollection<CampaignSummaryModel>(campaigns);
var salesObservable = new ObservableCollection<SalesSummaryModel>(salesSummary);
Campaigns = campaignsObservable;
Sales = salesObservable;
_isFetchingData = false;
return Task.CompletedTask;
});
}
here is the partial xaml code.
<dataGrid:SfDataGrid x:Name="SalesGrid"
ItemsSourceChanged="DataGrid_ItemsSourceChanged"
AutoExpandGroups="False"
ItemsSource="{Binding Campaigns}"
ColumnSizer="Star"
AutoGenerateColumns="False"
AllowGroupExpandCollapse="True"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
GroupingMode="Multiple"
AllowSorting="True" >
......
......
......
<dataGrid:SfDataGrid.CaptionSummaryRow>
<dataGrid:GridSummaryRow ShowSummaryInRow="True" Title="Total: {NetPrice}, {DateStr}">
<dataGrid:GridSummaryRow.SummaryColumns>
<dataGrid:GridSummaryColumn Name="DateStr" Format="{}{DateStr}" MappingName="DateStr" SummaryType="Custom" CustomAggregate="{StaticResource gridAggregate}" />
<dataGrid:GridSummaryColumn Name="NetPrice" Format="{}{NetPrice}" MappingName="NetPrice" SummaryType="Custom" CustomAggregate="{StaticResource gridAggregate}" />
</dataGrid:GridSummaryRow.SummaryColumns>
</dataGrid:GridSummaryRow>
</dataGrid:SfDataGrid.CaptionSummaryRow>
<dataGrid:SfDataGrid.GroupColumnDescriptions>
<dataGrid:GroupColumnDescription ColumnName="PeriodDate"/>
</dataGrid:SfDataGrid.GroupColumnDescriptions>
</dataGrid:SfDataGrid>
and this works fine when it is first binded but when i update the data from the server according to parameters that the user is changing i am getting a object reference not to set an instance of object exception. Do you have any idea or suggestions about it?
here is the partial stacktrace for the error that i am getting.
at Syncfusion.SfDataGrid.XForms.CaptionSummaryRowControl.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0002f] in <97e0e93585274364a86d4de6550b97c6>:0
at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
at Xamarin.Forms.Layout.ForceLayout () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:125
at Syncfusion.SfDataGrid.XForms.VisualContainer.ArrangeRows () [0x00773] in <97e0e93585274364a86d4de6550b97c6>:0
at Syncfusion.SfDataGrid.XForms.VisualContainer.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00000] in <97e0e93585274364a86d4de6550b97c6>:0
at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
at Syncfusion.SfDataGrid.XForms.VisualContainer.OnSizeAllocated (System.Double width, System.Double height) [0x0041c] in <97e0e93585274364a86d4de6550b97c6>:0
As a note if i do not create it with new ObservableCollection<CampaignSummaryModel>(campaigns);
then i don't get the error but in groupsummary the aggregate functions are not right. it shows only the first element's price instead of sum.
Thank you for the assistance.