RE: Subgrid/view Pagination not working for Virtual Entity
Hello,
you need to develop all pagination handling, interpreting the queryexpression pageinfo received in the plugin.
Reading the pageinfo:
if (query.PageInfo != null)
{
pageNumber = query.PageInfo.PageNumber;
pageSize = query.PageInfo.Count;
offset = $" OFFSET {(pageNumber - 1) * pageSize} ROWS FETCH NEXT {pageSize + 1} ROWS ONLY";
}
Editing the SQL query with the offset and doing a count query...:
command.CommandText = $"SELECT FIELDS FROM TABLE{orderString}{offset}";
queryCount = $"SELECT COUNT(*) FROM TABLE";
Informing the entity collection about the presence of new records:
if (readerCount.HasRows)
{
while (readerCount.Read())
if (!readerCount.IsDBNull(0)) total = readerCount.GetInt32(0);
collection.MoreRecords = total > pageNumber * pageSize;
collection.PagingCookie = "<cookie page='" + pageNumber + "'> <ENTITY_NAME last='{" + collection.Entities[collection.Entities.Count - 1].Id + "}' first='{" + collection.Entities[0].Id + "}' /> </cookie>";
collection.TotalRecordCount = total;
}