Skip to content
Discussions/App Development/Is Pagination and sorting supported in DamlForum ↗

Is Pagination and sorting supported in Daml

App Development11 posts439 views1 likesLast activity Dec 2021
EN
Enthusiast-BlockOP
Dec 2021

I have created records in Fabric Ledger using Daml. Suppose I have 100 contracts of a particular template.
I want to fetch sorted records using pagination size.

Example :- Suppose, I would specify the page size as 10 and sorting order as asc. It should fetch all records with 10 per page and sorted in ascending order.

Is the functionality available using Daml?

CO
cocreature
Dec 2021

Hi @Enthusiast-Block, there is no pagination or sorting on either the gRPC API or the JSON API.

For the gRPC API the ACS is streamed in chunks but you cannot resume that stream like you could for pagination.

EN
Enthusiast-Block
Dec 2021

Hi @cocreature . Thanks for the response.
Can you elaborate more about the last statement - connecting it with my example.

EN
Enthusiast-Block
Dec 2021

Also, can I restrict the number of contracts I fetch from the ledger. I would give it in JSON API, that it should only fetch 10 records and those number of records should only be fetched.

ST
stefanobaghino-da
Dec 2021

Limiting is not available either.

EN
Enthusiast-Block
Dec 2021

Hi @stefanobaghino-da , @cocreature . In my use case, I want to limit the number of contracts that I fetch from Fabric ledger, as it takes a lot of time to fetch those. So, I want to either filter it and fetch only limited number of contracts or implement some sort of pagination where in it retrieves some contracts in one click and then it retrieves other contracts in simultaneous clicks.

Is there any way to achieve this functionality.
I am interacting with Fabric Network using DAML JSON APIs.

ST
stefanobaghino-da
Dec 2021

As mentioned, those features are not available on the HTTP-JSON API. My recommendation would be for you to use the Ledger API directly and build a local query store analogous to the one kept by the HTTP-JSON API that implements rich query capabilities (including pagination and limiting) that match your requirements.

EN
Enthusiast-Block
Dec 2021

Hi @stefanobaghino-da,
Can you point me to an example code that uses DAML Ledger API?

ST
stefanobaghino-da
Dec 2021

The Ledger API documentation is here (for version 1.18.0). It includes documentation on the Ledger API and the Java bindings.

A comprehensive list of examples is here, including examples using the Java bindings.

EN
Enthusiast-Block
Dec 2021

Thanks @stefanobaghino-da,

I ran through the example of NodeJS - GitHub - digital-asset/ex-tutorial-nodejs: An interactive tutorial to get started with the Node.js bindings for DAML

Now, When I am fetching contracts using -

const request = {
begin: { offsetType: ‘boundary’, boundary: ledger.LedgerOffsetBoundaryValue.BEGIN },
filter: { filtersByParty: filtersByParty }
};
const transactions = client.transactionClient.getTransactions(request);

How would I be able to support Pagination, sorting of contracts of a particular template?

ST
stefanobaghino-da
Dec 2021

The examples shown in that page are very extensive, please note that the Node.js bindings are deprecated since a long time. The only supported set of bindings is the Java one (unless you want to generate the gRPC bindings yourself, of course).

In general, you would have to persist your contracts on a separate database with the data laid out as per your requirements and implement pagination and sorting based on that.

← Back to Discussions