Frontend School

Build a Paginated Trade History Table

Machine Coding
medium

Build a Paginated Trade History Table

Medium
React
TypeScript
Pagination
UI
State Management

Overview

At Zerodha, users frequently need to review their past trading activity. Displaying large datasets efficiently is crucial for a smooth user experience. This problem challenges you to build a robust and user-friendly pagination component for a simulated trade history table, mirroring the functionality found in real-world financial applications.

What you need to do / Task

Your primary task is to implement a PaginatedTable React component that displays a list of trade entries with a functional pagination control.

  1. Implement Pagination Logic: Based on the data prop (an array of Trade objects) and itemsPerPage prop, calculate the total number of pages and determine which subset of data should be displayed for the current page.
  2. Render Trade Data: Display the trades for the current page in a table format.
  3. Build Pagination Controls: Create a set of controls below the table that allows users to navigate through pages.
    • Include 'Previous' and 'Next' buttons.
    • Include clickable page numbers. For a large number of pages, use an ellipsis (...) to represent skipped pages. For example, if there are 20 pages and the current page is 5, display something like: Previous 1 ... 4 5 6 ... 20 Next.
  4. Handle Navigation: Implement handlers for clicking 'Previous', 'Next', and individual page number buttons to update the displayed page.
  5. Manage UI State: Visually indicate the currently active page and disable 'Previous'/'Next' buttons when they are not applicable (e.g., 'Previous' on the first page).

UI/UX expectations

  • The table should clearly display trade details (ID, Symbol, Quantity, Price, Type, Status, Timestamp).
  • The pagination controls should be positioned below the table, horizontally centered.
  • 'Previous' and 'Next' buttons should be clearly labeled.
  • Page number buttons should be distinct and clickable. The active page number should have a clear visual highlight (e.g., different background color).
  • When 'Previous' or 'Next' buttons are disabled, their appearance should reflect this (e.g., reduced opacity, greyed out).
  • The ellipsis (...) should be non-clickable and serve purely as a visual separator.

Acceptance criteria

  • The table correctly displays only the items corresponding to the current page and itemsPerPage.
  • Clicking 'Previous' navigates to the prior page, unless on the first page.
  • Clicking 'Next' navigates to the subsequent page, unless on the last page.
  • Clicking an individual page number button directly jumps to that page.
  • The active page number is visually highlighted.
  • The 'Previous' button is disabled when the user is on the first page.
  • The 'Next' button is disabled when the user is on the last page.
  • Pagination controls dynamically adjust to the total number of pages, correctly displaying page numbers and ellipses for scenarios with many pages (e.g., > 10 pages total).
  • The UI remains responsive and functional when changing itemsPerPage (though this will be a fixed prop for this problem, the component should handle it correctly).

Constraints

Constraints & assumptions

  • You will be working with local mock data provided in the starter code; no external API calls are required.
  • The itemsPerPage prop will be a positive integer.
  • Focus on client-side pagination logic. Data manipulation should occur within the PaginatedTable component.
  • The UI should be built using React and TypeScript.
  • Basic styling is provided; focus on functionality over elaborate design.

Out of scope

  • Server-side pagination implementation.
  • Advanced features like sorting, filtering, or search functionality.
  • Implementing a dynamic itemsPerPage selector (it will be a fixed prop).
  • Extensive error handling beyond basic UI states.

What interviewers evaluate

  • Correctness and efficiency of pagination logic.
  • Effective use of React state management and component structure.
  • Adherence to UI/UX and functional acceptance criteria.
  • Code readability, maintainability, and use of TypeScript.

Loading editor...