Build a DataTable component that shows a list of people in a <table>, one page at a time, with controls to move between pages and to pick how many rows a page holds. Admin dashboards are full of these.
<DataTable rows={[{ id: 1, name: "Asha", age: 31, occupation: "Engineer" }]} />
Props:
rows: an array of { id, name, age, occupation } objects. id is unique. Defaults to []. You can assume it does not change after the first render.Table:
id, name, age and occupation, one per cell, in the order they appear in rows.rows is empty, the body has a single row with one cell that reads No data.Controls, below the table:
<select> labelled Rows per page with the options 5, 10 and 20. It starts at 5.Page X of Y, for example Page 2 of 3.Rules:
X shows rows (X - 1) * size + 1 through X * size (the last page may hold fewer).Y is the number of pages needed for all rows. An empty table still counts as Page 1 of 1.With 12 people and the default page size:
Page 1 of 3. Previous is disabled.Page 3 of 3 and Next is disabled.10 in Rows per page. The table shows people 1 to 10 and the status reads Page 1 of 2.<DataTable rows={[{ id: 1, name: "Asha", age: 31, occupation: "Engineer" }]} />