Guide 2.14: Developer Guide

Pagination with SdashAPI

Unlike traditional APIs that manage lists of users or products using strict `page` and `offset` parameters, SdashAPI is designed specifically to generate randomized examination papers. Because questions are pulled randomly from the bank to prevent test predictability, traditional server-side pagination is not natively supported via the `limit` parameter alone.

Client-Side Pagination

2.14.1

If you want to build a UI that shows 10 questions per page with "Next" and "Previous" buttons, the best approach is to request a large batch of questions from the server (e.g., limit=50) and then paginate that array directly on the frontend using JavaScript.

const questionsPerPage = 10;
let currentPage = 1;
let allQuestions = []; // Array of 50 questions fetched from API

function renderPage(page) {
  const startIndex = (page - 1) * questionsPerPage;
  const endIndex = startIndex + questionsPerPage;
  
  // Slice the array to get only the 10 questions for the current page
  const questionsToRender = allQuestions.slice(startIndex, endIndex);
  
  displayQuestionsInDOM(questionsToRender);
}

Managing State in Frameworks

2.14.2

If you are using a framework like React or Vue, client-side pagination becomes even easier. You simply store the massive 50-item array in your state (useState) and use a computed value or derived state to calculate which slice of the array should be rendered based on the current page number variable.

Fetching Additional Batches

2.14.3

If the user reaches the very end of your 50-question array, you can make a fresh API call to fetch another batch of 50 questions, append them to your existing array, and allow the user to continue paginating seamlessly.

Need specific keywords?

Next, we will explore techniques for searching the question bank.

Next Guide: Searching Question Bank →
Avatar

How can we help?

We reply immediately

Hello! 👋 How can we help you today?