How to perform server-side pagination on a DynamoDB table

I've been trying to configure server-side pagination on a table displaying data from a DynamoDB database but i've been running into errors and can't find evidence of anyone having done it successfully anywhere online.

I've made a few different attempts, all revolving around DynamoDB's main method of pagination (as far as i'm aware); utilising "LastEvaluatedKey" and "ExclusiveStartKey:

  1. Cursor based pagination - I set "Next cursor" to {{ ddbQueryPlaceholder.data.LastEvaluatedKey }} and in the query itself I set ExclusiveStartKey to {{ ddbTablePlaceholder.pagination.afterCursor }} with a limit which matches the page size (100). However, in this scenario the value of afterCursor remains null whenever I change page - resulting in the same results being retrieved everytime I change page. It also for some reason limits the pages to 2, even though "Has next page" is true and I know there are more results to come.
  2. Limit offset based pagination - I set ExclusiveStartKey to be {{ddbQueryPlaceholder.data.LastEvaluatedKey }} however this results in a dependency cycle error causing the page to crash..

I've tried variations on these two methods but the results are the same - either page changes do not update results, or the page will just crash.

Hey @tg295!

Can you try sticking with cursor-based pagination and setting "Next cursor" to {{ JSON.stringify(ddbQueryPlaceholder.data.LastEvaluatedKey) }} ? Stringifying the object you're getting should prevent it from being passed as null, in the query itself, you'll then want to set ExclusiveStartKey to {{ JSON.parse(ddbTablePlaceholder.pagination.afterCursor) }}.

Let me know if that works!

Hi Kabirdas,

Thanks for getting back to me. This worked like a charm so thanks for that too!

That being said, after successfully enabling server-side pagination, i've now found that none of the sorting or filter options are working on any of the columns in my table - do you have any idea why that might be?

Best,

Theo

Ah I see there are a few existing issues opened in regards to this: Sort columns when server side pagination is enabled - #8 by Kabirdas

Yep! The dev team is also looking into some additional sorting improvements for the new table. I'll try and let you know here as well when there's a relevant update!

Glad to hear server-side pagination is at least working for the time being albeit without sorting :slightly_smiling_face: