We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SfDataPager PageSize Grouping sfDatagrid

I have a sfdatagrid with a group column and I want to use SfDataPager for paging.I have defined PageSize = 10 in SfDataPager but The pagination is dividing the group if  there are more than 10 elements and there are differents page with the same year. I would like that the pagination was in the group, in this example, if PageSize = 10 I would like to have 10 differents years per pageIt is posible?

6 Replies

MK Muthukumar Kalyanasundaram Syncfusion Team April 11, 2017 08:38 AM UTC

Hi Salva, 
 
Thank you for contacting Syncfusion support.

We have checked your query and prepared simple sample based on your requirement. In that sample, we have grouped each page based on the “EmployeeID”and page index on each page. So each page will show the records for corresponding EmployeeID in the page. For example, in the first page EmployeeID  with value “1” will be shown, next page EmployeeID records with value 2 will be shown and so on. In the same way, you can control the records that needs to be displayed on page based on data. For your reference, we have added the code and sample in the below location,
 
 
Code Snippet: 
 
 
dataPager.OnDemandLoading += dataPager_OnDemandLoading;                               
 
private void dataPager_OnDemandLoading(object sender, Syncfusion.UI.Xaml.Controls.DataPager.OnDemandLoadingEventArgs args) 
{ 
    //Finding the Page Index 
    int pgIndex = (args.StartIndex + 1) / dataPager.PageSize; 
    //Getting the records for page based on EmployeeID and PageIndex. So each page will show records for particular EmployeeID. 
    var pagesource = source.Where(ord => ord.EmployeeID == pgIndex + 1); 
    //Loading data for page 
    dataPager.LoadDynamicItems(args.StartIndex, pagesource); 
} 
 
 
 
SfDataPager allows you to load data for current page alone using OnDemandPaging instead of loading data for all pages. For more details, you can refer below documentation link, 
 
 
Please let us know if you have any query. 
 
Regards, 
Muthukumar K 
 



SA Salva April 18, 2017 10:07 AM UTC

I forgot to mention it but I am using MVVM.

I have been looking at the solution and others the examples of load data in on-demand but I don´t know how to do it with MVVM.

Do you have any example in MVVM?


MK Muthukumar Kalyanasundaram Syncfusion Team April 20, 2017 03:52 AM UTC

Hi Salva, 

Thanks for the update. 

We have analyzed your query. We have created simple sample based on your requirement. Could you please refer the code snippet and attached sample in below location. In the sample, we have loaded the data in OnDemand, then we have used interaction behavior to achieve your requirement by overriding the OnAttached() method and handling Loaded event.  

Code Snippet: Xaml 

<syncfusion:SfDataGrid x:Name="dataGrid" 
                            AllowFiltering="True" 
                            AllowResizingColumns="True" 
                            AutoGenerateColumns="False" 
                            AllowSorting="True" 
                            ItemsSource="{Binding Path=PagedSource, 
                                          ElementName=sfDataPager}" 
                            NavigationMode="Row" 
                            RowHeight="24.5"> 
 
<interactivity:Interaction.Behaviors> 
    <local:OnDemandLoadBehavior /> 
</interactivity:Interaction.Behaviors> 


Code Snippet: C# 

public class OnDemandLoadBehavior : Behavior<MainWindow> 
{ 
    private EmployeeInfoRespository repository; 
    private List<Employees> source; 
    protected override void OnAttached() 
    { 
        AssociatedObject.Loaded += OnAssociateObjectLoad; 
        repository = new EmployeeInfoRespository(); 
        source = repository.GetEmployeesDetails_List(2000); 
    } 
 
    void OnAssociateObjectLoad(object sender, System.Windows.RoutedEventArgs e) 
    { 
        AssociatedObject.sfDataPager.OnDemandLoading += OnDemandLoading; 
        AssociatedObject.sfDataPager.MoveToFirstPage(); 
    }       
    void OnDemandLoading(object sender, OnDemandLoadingEventArgs args) 
    { 
        AssociatedObject.sfDataPager.LoadDynamicItems(args.StartIndex,source.Skip(args.StartIndex).Take(args.PageSize)); 
    } 
 
    protected override void OnDetaching() 
    { 
        AssociatedObject.Loaded -= OnAssociateObjectLoad; 
        AssociatedObject.sfDataPager.OnDemandLoading -= OnDemandLoading; 
    } 
} 



Please let us know if you have any query. 

Regards, 
Muthukumar K 



SA Salva April 20, 2017 09:50 AM UTC

This is Ok but, now I want to join this example with filtering and to have datagrid with datapager and filtering with MVVM.I've attached a .rar, this rar is based in filtering_demo, but I have modified the code (VS 2015), but it is not working, with the helper behavior public class OnDemandLoadBehavior : Behavior I can load the datapager on demanding but I don´t know how to join it with the filtering


SA Salva replied to Salva April 20, 2017 09:52 AM UTC

This is Ok but, now I want to join this example with filtering and to have datagrid with datapager and filtering with MVVM.I've attached a .rar, this rar is based in filtering_demo, but I have modified the code (VS 2015), but it is not working, with the helper behavior public class OnDemandLoadBehavior : Behavior I can load the datapager on demanding but I don´t know how to join it with the filtering

Here is the file

Attachment: FilteringDemo_6248da91.rar


MK Muthukumar Kalyanasundaram Syncfusion Team April 25, 2017 04:14 AM UTC

Hi Salva, 
 
Thanks for the update. 
 
We have analyzed your provided sample. We have prepared sample based on your requirement(to filter the record with MVVM pattern in OnDemandCollection) as shown like below code, 
 
Code Snippet: 
 
protected override void OnAttached() 
{ 
    viewmodel = AssociatedObject.DataContext as EmployeeInfoViewModel; 
    AssociatedObject.Loaded += OnAssociateObjectLoad;     
    (AssociatedObject.DataContext as EmployeeInfoViewModel).FilterChanged += OnFilterChanged; 
    empsource = viewmodel.EmployeeDetails; 
} 
 
 
IEnumerable<Employees> empsource; 
private void OnFilterChanged() 
{ 
    empsource = viewmodel.EmployeeDetails.Where(emp => viewmodel.FilerRecords(emp)); 
    var totalcount = empsource.Count(); 
    var pagecount = 0; 
    if (totalcount < this.AssociatedObject.SfDataPager.PageSize) 
        pagecount = 1; 
    else 
        pagecount = totalcount / this.AssociatedObject.SfDataPager.PageSize; 
 
    if (this.AssociatedObject.SfDataPager.PageCount != pagecount) 
        this.AssociatedObject.SfDataPager.PageCount = pagecount; 
 
    (this.AssociatedObject.sfGrid.View as PagedCollectionView).ResetCache(); 
    (this.AssociatedObject.sfGrid.View as PagedCollectionView).ResetCacheForPage(this.AssociatedObject.SfDataPager.PageIndex); 
    (this.AssociatedObject.sfGrid.View as PagedCollectionView).MoveToFirstPage(); 
} 



Please let us know if you have any query. 

Regards, 
Muthukumar K 


Loader.
Up arrow icon