0.5.2 • Published 3 years ago

gridler v0.5.2

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

gridler

Table of Contents

Installation

npm install gridler

Import

import Gridler from "gridler";

Props

NameTypeDefaultDescription
columns*GridlerColumn[]List of columns of type 'GridlerColumn'. See GridlerColumn below for more details.
rows*object[]List of rows
density'compact' | 'default' | 'comfort''default'Sets the density of the rows.
filterobjectSets the initial filter criteria. For example {id: 5, name: 'Doe'}
sortobjectSets the initial sort field and order. For example { field: 'id', order:'asc'}
disableColumnSelectorbooleanfalseIf true, the column selector is disabled.
disableDensitySelectorbooleanfalseIf true, the density selector is disabled.
local'en' | 'de''en'Sets which set of text labels should be used in the Gridler
onAddClick() => voidIf defined, a 'Add' button will be displayed in the toolbar and the callback fired when a click event comes
onRowClick(row, event: React.MouseEvent) => voidCallback fired when a click event comes from a row container element.

GridlerColumn

NameTypeDefaultDescription
field*stringName of the row-object field to use in this column
descriptionstringdescription of the column
filterablebooleantrueif true the rows can be filtered by the value in this column
headerNamestringcolumn${index}Label for the column header
hidebooleanfalseif true the column will not be displayed
renderHeader() => nodeSet this function if you want to render more than a simple label as header
renderCell(row) => nodeSet this function if you want to render a node as row value
sortablebooleantrueif true, the rows can be sorted by the value in this column
sortComparator(a,b) => integerYou can set a custom sort comparator to define how this column should be sorted
type'text' | 'number' | 'date' | 'dateTime' | 'boolean' | 'select''text'the type of the column
valueFormatter(value) => stringYou can set a value formatter to format the value for display without changing the underlaying value (for example '0.2' to '20%')
valueGetter(row) => stringUse this function if the column doesn´t have a corresponding value, or if you want to render a combination of different fields.
widthinteger200width of the column

Row rendering

By default, the gridler renders the value as a string in the cell. It resolves the rendered output in the following order:

  1. renderCell(row) => ReactElement
  2. valueFormatter(value) => string
  3. valueGetter(row) => string
  4. rowfield

Getting Started

import Gridler from "gridler";

const columns = [
  {
    field: 'id',
    headerName: 'ID',
    width: 50,
  }, {
    field: 'name',
    headerName: 'Name',
    valueGetter: ({row}) => `${row.firstname} ${row.lastname}`,
    width: 200,
  }, {
    field: 'email',
    headerName: 'Email',
    width: 250,
  },
];

const rows = [
  { id: 1, firstname: 'John', lastname: 'Doe', email: 'john@thisisnotareal.adress'},
  { id: 1, firstname: 'Jane', lastname: 'Doe', email: 'jane@thisisnotareal.adress'},
];

export default function App() {
  return (
    <Gridler 
      columns={columns}
      rows={rows}
    />
  );
};
0.5.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.4.1

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago