Hi,
I have an issue using the Behaviour for using the SfDataPager with a ListView. The problem comes from trying to access the DataPager using the bindable.FindByName("dataPager"); method as this always returns null as the DataPager is part of a DataTemplate.
My XAML code is as follows: XAML:
XAML:
<syncfusion:sflistview x:name="JobListView" autofitmode="Height" horizontaloptions="CenterAndExpand" headersize="256" itemtemplate="{StaticResource JobListItem}" selectionmode="None" itemtapped="JobListView_ItemTapped">
<syncfusion:sflistview.headertemplate>
<datatemplate x:name="JobListHeaderTemplate">
<grid x:name="JobHeaderGrid" backgroundcolor="Transparent" heightrequest="256">
...
</grid>
</datatemplate>
</syncfusion:sflistview.headertemplate>
<syncfusion:sflistview.footertemplate>
<datatemplate x:name="JobListFooterTemplate">
<grid x:name="JobFooterGrid" backgroundcolor="White" verticaloptions="FillAndExpand">
<grid.rowdefinitions>
<rowdefinition height="Auto">
<rowdefinition height="*">
</rowdefinition></rowdefinition></grid.rowdefinitions>
<sfpager:sfdatapager x:name="dataPager" heightrequest="45" horizontaloptions="CenterAndExpand" useondemandpaging="True" displaymode="PreviousNextNumeric" numericbuttoncount="5" pagesize="10" buttonshape="Rectangle" appearancemanager="{StaticResource customAppearance}">
<label .....="">
</label></sfpager:sfdatapager></grid>
</datatemplate>
</syncfusion:sflistview.footertemplate>
</syncfusion:sflistview>
The Behaviour is the same as one of the samples: The part that fails is this:
protected override void OnAttachedTo(ContentPage bindable)
{
listView = bindable.FindByName("listView");
dataPager = bindable.FindByName("dataPager"); <-- This cannot be found
viewModel = new RequisitionListViewModel();
dataPager.OnDemandLoading += DataPager_OnDemandLoading;
base.OnAttachedTo(bindable);
} Are there any other ways of achieving the desired results?
Thanks for any help.
Andrew
Hi,
Thanks for the reply. I have looked at the documentation referenced in the above answer but I am not able to see how that would help the issue outlined in the original question ie. How to get a reference to the dataPager control in the Behaviour.
It seems I will not be able to use the Behaviour approach to get the reference to the DataPager.
I have tried a different approach with a sample included. I am now finding another issue:
private void dataPager_OnDemandLoading(object sender, Syncfusion.SfDataGrid.XForms.DataPager.OnDemandLoadingEventArgs e)
{
var source = App.Locator.Main.Items.AsEnumerable();
var dataPager = (sender as SfDataPager);
dataPager.LoadDynamicItems(e.StartIndex, source.Skip(e.StartIndex).Take(e.PageSize));
JobListView.ItemsSource = dataPager.PagedSource; <-- Throws source is not IEnumerable<>
dataPager.PagedSource.Refresh();
}
The highlighted line throws an error of source is not IEnumerable<> at runtime.
I have included the project.
Any ideas?
Thanks
Andrew
Attachment: DataPagerSample_f47e3d7f.zip
|
private void dataPager_OnDemandLoading(object sender, Syncfusion.SfDataGrid.XForms.DataPager.OnDemandLoadingEventArgs e)
{
var source = App.Locator.Main.Items.AsEnumerable();
var dataPager = (sender as SfDataPager);
var items = source.Skip(e.StartIndex).Take(e.PageSize);
dataPager.LoadDynamicItems(e.StartIndex, items);
JobListView.ItemsSource = items.AsEnumerable();
(dataPager.PagedSource as PagedCollectionView).ResetCache();
} |