Skip to content

Issue with DataTable (Externally controlled data) #2

@EVRUSIN

Description

@EVRUSIN

When we externally control data in DataTable component by passing totalElements, we click on last page. Then button Next is disabled, but you can still click on it and go to next page, when there is no elements.
hasMore doesn't affect anything

import { Content, Row, Col, Box, Button, Inputs, DataTable } from "adminlte-2-react"
...
getData() {
    this.setState({ loading: true });
    const waitTime = Math.random() * 2000;
    setTimeout(() => {
      const { order, activePage, selectedEngine } = this.state;
      let localData = data;
      const filteredData = localData.sort((a, b) => {
        if (a[order.column].toLowerCase() < b[order.column].toLowerCase()) { return order.direction === 'asc' ? -1 : 1; }
        if (a[order.column].toLowerCase() > b[order.column].toLowerCase()) { return order.direction === 'asc' ? 1 : -1; }
        return 0;
      }).slice(10 * activePage, 10 * activePage + 10);
      const hasMore = filteredData.slice(10 * activePage, 10 * activePage + 10).length === 10;
      this.setState({ filteredData, loading: false, hasMore });
    }, waitTime);
  }
...
<DataTable
  id="external-data"
  columns={firstColumns}
  options={{
    autoWidth: false,
    select: true,
    rowId: 'browser',
  }}
  data={filteredData}
  page={activePage}
  pageSize={10}
//  hasMore={hasMore}
  totalElements={(filteredData && localData.length) || 0}
  onPageChange={(page) => {
    this.setState({ activePage: page });
    this.getData();
  }}
/>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions