Loading...

PCF Dataset Paging in Model vs Canvas Apps

PCF Dataset Paging in Model vs Canvas Apps

One of the recent additions to PCF for Canvas Apps is the ability to bind dataset PCF controls to datasets in a Canvas App. A challenge that faces all PCF developers is if their control should support both Model AND Canvas – so with this in mind you need to be aware of the differences in the way that data is paged.

This post demonstrates how the paging API works in Model and Canvas and highlights the differences. In my tests, I used an entity that had 59 records and spanned 3 pages of 25 records per page.

loadNextPage/loadPreviousPage

There are two ways of paging through your data:

  1. Incrementally load the data using loadNextPage
  2. Page the data explicitly using loadExactPage
    In Model Apps, when you call loadNextPage, the next page of data will be added on top of the existing dataset.sortedRecordIds – whereas in Canvas, you will get a reset set of records that will just show the page that you have just loaded.

This is important if you control aims to load all records incrementally or uses some kind of infinite scrolling mechanism.

This is how nextPage/previousPage works in Canvas Apps

This is how nextPage/previousPage works in Model Apps

Notice how the totalRecordsLoaded increases with each page for Model, but for Canvas it shows only the number of records on that page.
You might think that using this approach would be more efficient because it uses the fetchXml paging cookie - well from what I can see it doesn't seem to be any different to just specifying the page in the fetchXml - and has the same performance as loadExactPage...

loadExactPage

When you want to show a specific page – jumping over other pages without loading them, you can use ‘loadExactPage’. This method is not currently documented – but it is mentioned by the PCF team in the forums
This method will load the records for the specific page and so dataset.sortedRecordIds will only contain that page – this is the same on both Canvas and Model!

Notice that if you load a specific page, the hasNextPage and hasPreviousPage is updated to indicate if you can move back or forwards. This would only help when using loadExactPage in Model Apps, because when using loadNextPage in Model Apps, you will never get hasPreviousPage == true because you are loading all the records incrementally rather than a specific page.

This is how loadExactPage works in Canvas Apps

This is how loadExactPage works in Model Apps

Notice total records loaded shows only the number of records in that page.

totalResultCount

This property should give you how many records there are in the current dataset – however, in Canvas it only gives you the number of records that have been loaded via the paging methods. If you look at the comparisons above, you’ll see that the Canvas totalResultCount goes up with each page, but in Model, it remains the total record count.
Interestingly this property is not actually documented – however it’s in the Typescript definitions.

The Future

It’s not clear if we will see a completely unified experience between Canvas and Model with PCF controls – but I’ll update this post if anything changes!

Published on:

Learn more
Develop 1 - Dynamics 365 Architecture Services
Develop 1 - Dynamics 365 Architecture Services

Share post:

Related posts

Power Apps – Public preview for Microsoft 365 Copilot chat in canvas apps

We are announcing Microsoft 365 Copilot chat for canvas apps in Power Apps. This feature is now available for public preview. How does this af...

4 days ago

How to add smart offline capabilities in embedded canvas apps

Learn how to smartly add offline capabilities in embedded canvas apps! You can store multiple records related to multiple different records! T...

5 days ago

How to add offline capabilities in embedded canvas apps

Have you ever wanted to add offline or caching capabilities to embedded canvas apps? Learn a very simple way to make that happen! The post How...

5 days ago

Power Apps – Enable online mode to access Dataverse for Canvas apps

We are announcing the ability to enable online mode to access Dataverse for Canvas apps in Power Apps. This feature will reach public preview ...

6 days ago

New quality updates to modern controls in canvas apps

This release delivers quality and reliability improvements across nine modern controls in canvas apps, including Combo Box, Text Input, and Da...

19 days ago

How to change the attachment on a note in canvas apps

Changing the attachment of a note is super easy in a model-driven app, not so much in a canvas app. Learn how to do it! The post How to change...

1 month ago

How to add a title and description when uploading an attachment in canvas apps

Uploading attachments through model-driven apps allows you to specify title & description but canvas app doesn't. Learn how you can! The...

1 month ago

How to work with Dataverse Attachments in canvas apps

Learn how to work with the Attachments Dataverse table in canvas apps. We will review how to create, delete, and view existing attachments! Th...

1 month ago

How to work with Dataverse Notes in canvas apps

Learn how to work with the Notes Dataverse table in canvas apps. We will review how to create, edit, delete, and view existing notes! The post...

1 month ago

Best Practices: Canvas Apps & Power Pages Integration

Golden Rule:Canvas Apps are NOT designed for external users. Power Pages is.Most best practices focus on when to avoid integration and how to ...

1 month ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy