4.1.9 • Published 2 years ago

bpk-component-datatable-css v4.1.9

Weekly downloads
182
License
Apache-2.0
Repository
github
Last release
2 years ago

bpk-component-datatable

Backpack datatable component.

Installation

npm install bpk-component-datatable --save-dev

Usage

import React from 'react';
import { BpkDataTable, BpkDataTableColumn } from 'bpk-component-datatable';

const rows = [
  { name: 'Jose', description: 'Software Engineer' },
  { name: 'Rolf', description: 'Manager' }
]

const onRowClick = row => alert(JSON.stringify(row));

export default () => (
  <BpkDataTable rows={rows} height={200} onRowClick={onRowClick}>
    <BpkDataTableColumn
      label={'Name'}
      dataKey={'name'}
      width={100}
    />
    <BpkDataTableColumn
      label={'Description'}
      dataKey={'description'}
      width={100}
      flexGrow={1}
    />
  </BpkDataTable>
);

By default BpkDataTable sorts the column using the value of dataKey. For use cases where the data might more complex and requires custom sorting you can pass a sort function along with sortBy and sortDirection and they will be handled as explained in react-virtualized's docs

import React from 'react';
import { BpkDataTable, BpkDataTableColumn } from 'bpk-component-datatable';
import _sortBy from 'lodash/sortBy';

const complexRows = [
    {
      name: 'Jose',
      description: 'Software Engineer',
      seat: { office: 'London', desk: 10 },
    },
    {
      name: 'Rolf',
      description: 'Manager',
      seat: { office: 'Barcelona', desk: 12 },
    },
    {
      name: 'John',
      description: 'Software Engineer',
      seat: { office: 'Barcelona', desk: 15 },
    },
];

let sortByValue = 'seat';
let sortDirectionValue = 'DESC';
const sortFunction = ({ sortBy, sortDirection }) => {
  if (sortBy === 'seat') {
    complexRows = _sortBy(complexRows, [
      row => row.seat.office,
      row => row.seat.desk,
    ]);
  } else {
    complexRows = _sortBy(complexRows, sortBy);
  }
  if (sortDirection === 'DESC') {
    complexRows.reverse();
  }
  sortByValue = sortBy;
  sortDirectionValue = sortDirection;
};

export default () => (
  <BpkDataTable
    rows={complexRows}
    height={200}
    sort={sortFunction}
    sortBy={sortByValue}
    sortDirection={sortDirectionValue}
  >
    <BpkDataTableColumn
      label="Name"
      dataKey="name"
      width={100}
    />
    <BpkDataTableColumn
      label="Description"
      dataKey="description"
      width={100}
    />
    <BpkDataTableColumn
      label="Seat"
      dataKey="seat"
      width={100}
      flexGrow={1}
      cellRenderer={({ cellData }) => (
        <React.Fragment>
          {cellData.office} - {cellData.desk}
        </React.Fragment>
      )}
    />
  </BpkDataTable>
);

Props

BpkDataTable

Supports all properties defined in Table (from react-virtualized), in addition to the following:

PropertyPropTypeRequiredDefault Value
rowsarrayOf(Object)true-
childrenarrayOf(BpkDataTableColumn)true-
heightnumbertrue-
widthnumberfalsefull width of parent
headerHeightnumberfalse60
rowHeightnumberfalse60
defaultColumnSortIndexnumberfalse0
sortfuncfalsenull
sortBystringfalsenull
sortDirectiononeOf('ASC', 'DESC')falsenull

BpkDataTableColumn

Supports all properties defined in Column (from react-virtualized)

4.1.9

2 years ago

4.1.7

2 years ago

4.1.5

2 years ago

4.1.4

2 years ago

4.1.2

2 years ago

4.1.1

2 years ago

4.0.4

2 years ago

4.0.10

2 years ago

4.0.1

2 years ago

4.0.2

2 years ago

4.0.16

2 years ago

4.0.11

2 years ago

4.0.13

2 years ago

4.0.0

3 years ago

3.0.13

3 years ago

3.0.10

3 years ago

3.0.8

3 years ago

3.0.7

3 years ago

3.0.6

3 years ago

3.0.5

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

2.3.7

3 years ago

3.0.0

3 years ago

2.3.5

3 years ago

2.3.4

3 years ago

2.3.3

3 years ago

2.3.2

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago

2.2.22

3 years ago

2.2.21

3 years ago

2.2.20

3 years ago

2.2.19

3 years ago

2.2.18

3 years ago

2.2.17

3 years ago

2.2.15

3 years ago

2.2.16

3 years ago

2.2.14

3 years ago

2.2.13

3 years ago

2.2.11

3 years ago

2.2.12

3 years ago

2.2.10

3 years ago

2.2.9

3 years ago

2.2.8

3 years ago

2.2.7

3 years ago

2.2.6

3 years ago

2.2.5

3 years ago

2.2.4

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.58

3 years ago

2.0.57

3 years ago

2.0.56

3 years ago

2.0.55

3 years ago

2.0.54

3 years ago

2.0.53

3 years ago

2.0.52

3 years ago

2.0.49

3 years ago

2.0.47

4 years ago

2.0.46

4 years ago

2.0.45

4 years ago

2.0.44

4 years ago

2.0.42

4 years ago

2.0.41

4 years ago

2.0.39

4 years ago

2.0.40

4 years ago

2.0.38

4 years ago

2.0.37

4 years ago

2.0.35

4 years ago

2.0.34

4 years ago

2.0.33

4 years ago

2.0.28

4 years ago

2.0.26

4 years ago

2.0.24

4 years ago

2.0.23

4 years ago

2.0.22

4 years ago

2.0.21

4 years ago