How to fetch only 10 rows per page?

In an interface we are showing grid with 4 columns and data is populated in it through query entity. So in query entity we are fetching all rows matching the search criteria with "local!paginginfo: a!pagingInfo(startIndex:1, batchSize: -1)". We are storing this query entity output in a cdt and using "ri!cdt.column name" to populate data in grid. But In Grid if we use "local!paginginfo: a!pagingInfo(startIndex:1, batchSize: 10)", to show 10 records per page, it is not returning data at all and if use "local!paginginfo: a!pagingInfo(startIndex:1, batchSize: length(ri!cdt.id))", it is returning all rows at a time. Please suggest how to fetch only 10 rows per page

OriginalPostID-200029

OriginalPostID-200029

  Discussion posts and replies are publicly visible

  • @divyav As per my understanding of the question, here goes the pseudocode of how you can sort the paging issue you have been experiencing:

    load(
    \tlocal!arrayOfCDTData:,
    \tlocal!pagingInfo:a!pagingInfo(startIndex:1,batchSize: 10),
    \twith(
    \ tlocal!datasubset: fn!todatasubset(local!arrayOfCDTData,local!pagingInfo),
    \ ta!gridField(
    \ t totalCount: local!datasubset.totalCount,
    \ t columns: {
    \ ta!gridTextColumn(
    \ t label: "",
    \ t data: index(local!datasubset.data,"",{}),
    \ t alignment: "LEFT"
    \ t),
    \ t
    \ t },
    \ t value: local!pagingInfo,
    \ t saveInto: local!pagingInfo
    \ t)
    \t)
    )

    If the issue isn't resolved, I would suggest you attaching the code snippet of what you have written so far and the practitioners here can guide you accordingly by revising it.
  • @divyav If you want to avoid querying the entity for the entire data in a single shot, you may do as follows:

    load(
    \tlocal!pagingInfo:a!pagingInfo(startIndex:1,batchSize: 10),
    \tlocal!datasubset:a!queryEntity(query:a!query(pagingInfo:local!pagingInfo)),
    \ta!gridField(
    \ ttotalCount: local!datasubset.totalCount,
    \ tcolumns: {
    \ ta!gridTextColumn(
    \ t label: "",
    \ t data: index(local!datasubset.data,"",{}),
    \ t alignment: "LEFT"
    \ t),
    \ t
    \ t},
    \ tvalue: local!pagingInfo,
    \ tsaveInto: {
    \ tlocal!pagingInfo,
    \ ta!save(local!datasubset,a!queryEntity(query:a!query(pagingInfo:local!pagingInfo)))
    \ t}
    \t)
    )

    This way, you can make a query and refresh the datasubset only when you interact with the grid in the interface.
  • 0
    Certified Associate Developer
    You can use below logic


    local!pagingInfo:a!pagingInfo(startIndex:1,batchSize:10),
    local!datasubset:todatasubset(ri!QueryData.data,local!pagingInfo)
    and use local!datasubset wherever required
  • Hi Divya -

    As a side consideration:
    Be careful using "batchSize: -1" in your queries.

    -1 is essentially an unlimited batch size.

    This setting will probably work well in early design and testing.
    However, if the data store entity being queried ever becomes very large, the Query Rule Limits might go into force, leading to user-facing unexpected behavior.