Understanding the Waiter.js API - GeeksRock/Waiter.js GitHub Wiki

Understanding the Waiter.js API


See the Pen Waiter.js Demo by Geeks Rock (@GeeksRock) on CodePen.

<script async src="//assets.codepen.io/assets/embed/ei.js"></script> ***

Waiter.takeDataOrder(data, records_per_page)
description: This is the starting point. Call this function to give your data order to your Waiter. Waiter.js will then evaluate your data order and create your pages, so that they are ready when you need them.
parameters:

  • data: [object array] This is the data that you want Waiter.js to separate into manageable pages.
  • records_per_page: [int] This number indicates the number of records you want Waiter.js to add to each page.

Waiter.takePageOrder(page_number, criteria, direction)
description: Use this function to request a specific page, with sorted data, from Waiter.js
parameters:

  • page_number: [int] Number indicating the page you want Waiter.js to serve up.
  • criteria: [string] Waiter.js will use this string as sort criteria, for serving up pages with sorted data.
  • direction: [int] Waiter.js will use this string as sort direction, for serving up pages with sorted data. Use 0 to request ascending and 1 to request descending.

returns: Array of objects

Note: You must supply both, criteria and direction, if you want Waiter.js to serve up your pages with sorted data. Otherwise, Waiter.js will serve up your pages with unsorted data, rather than throwing an error. If you don't need to offer sorting, use Waiter.serveSelectedPage() instead.


Waiter.serveNextPage() and Waiter.servePrevPage()
description: After you ask Waiter.js to take your data order, these functions serve up the next page or previous page, respectively.

returns: Array of objects


Waiter.serveSelectedPage(page_number)
description: Use this function to request a specific page from Waiter.js
parameters:

  • page_number: [int] Number indicating the page you want Waiter.js to serve up.

returns: Array of objects


Waiter.servePages() and Waiter.servePageData()
If you're curious about the pages Waiter.js has created for you, just ask the Waiter to show your pages menu.

If Waiter.js hasn't taken your data order yet, use: console.log(Waiter.takeDataOrder(data, records_per_page).servePages());
Otherwise, use: console.log(Waiter.servePages());

Likewise, you can use console.log(Waiter.servePageData()); to see a complete snapshot of the current state of your pages, as managed by Waiter.js

⚠️ **GitHub.com Fallback** ⚠️