Back

Error in implementing cursor pagination

  • 0
  • Databases
  • Web
mitsy0_0
3 Jun, 2023, 15:08

I'm following the docs, https://appwrite.io/docs/pagination#cursor-pagination, so do I need to write the code again and again for each page? And I'm getting an error saying Cannot read properties of undefined (reading 'length')

this is my function

TypeScript
               "647ac763cf53edxxxxx",
               "647ac820ba3852xxxxx",
               [
                   Query.orderDesc("age"),
                   Query.notEqual("age", ["invalid"]),
                   Query.limit(25)
               ]
           );
           const lastId = page1.documents[page1.documents.length - 1].$id;

           // Page 2
           const page2 =  databases.listDocuments(
               '647ac763cf53edxxxxx',
               '647ac820ba3852xxxxx',
               [
                   Query.limit(25),
                   Query.cursorAfter(lastId),
               ]
           );

           page1.then(function (response) {
               console.log(response.documents);
               var tableHTML = generateTable(response.documents);
               var tableContainer = document.getElementById('tableContainer');
               tableContainer.innerHTML = tableHTML;
           }, function (error) {
               console.log(error);
           });
           page2.then(function (response) {
               console.log(response.documents);
               var tableHTML = generateTable(response.documents);
               var tableContainer = document.getElementById('tableContainer');
               tableContainer.innerHTML = tableHTML;
           }, function (error) {
               console.log(error);
           });```
TL;DR
The user was encountering an error with cursor pagination implementation. They followed the appwrite.io documentation but received an error saying 'Cannot read properties of undefined (reading 'length')'. They included the code they were using for pagination. The user then stated that they have solved the error. There is no further information provided on how they resolved it.
Drake
3 Jun, 2023, 15:34

I highly suggest you do some research or tutorials on promises to understand how they work and how to use them

mitsy0_0
3 Jun, 2023, 19:25

I solved my error, thanks🫡

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more