Skip to content

Commit

Permalink
Listing: add props page and rowsPerPage
Browse files Browse the repository at this point in the history
  • Loading branch information
drublic committed Apr 11, 2021
1 parent 37d279e commit 133241b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ Data-Table to display data.
- `data: any[]`, data to display in table
- `order?: ENUM(asc | desc)`, direction in which to sort values, default `asc`
- `orderBy: string`, field name to use for sorting the table
- `page?: number`, page to show in current listing, default `0`
- `rowsPerPage?: number`, number of rows per page to show, default `10`
- `hasLoader?: boolean`, should a loader be displayed in table, default `false`
- `renderToolbarContent?: (selected) => ReactElement | null`, content to show in the toolbar (visible if content column is selected)
- `onUpdateSelection: function`, is called if a selection of a line is changed
Expand Down
8 changes: 6 additions & 2 deletions src/Listing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type Props = {
hasLoader?: boolean;
data: Record<string, any>[];
headers: Header[];
page?: number;
rowsPerPage?: number;
toolbarContent?: React.ReactNode;
onUpdateSelection?: (...args: any[]) => any;
onClick?: (...args: any[]) => any;
Expand All @@ -42,11 +44,13 @@ const Listing: FunctionComponent<Props> = ({
order: orderProp,
headers,
onUpdateSelection,
page: pageProp = 0,
rowsPerPage: rowsPerPageProp = 10,
...rest
}) => {
const node = useRef<any>();
const [page, setPage] = useState<number>(0);
const [rowsPerPage, setRowsPerPage] = useState<number>(10);
const [page, setPage] = useState<number>(pageProp);
const [rowsPerPage, setRowsPerPage] = useState<number>(rowsPerPageProp);
const [selected, setSelected] = useState<string[]>([]);
const [order, setOrder] = useState<"asc" | "desc">(orderProp || "asc");
const [orderBy, setOrderBy] = useState<string>(orderByProp || "id");
Expand Down

0 comments on commit 133241b

Please sign in to comment.