1.0.167 • Published 3 years ago

@postadress/react-simple-table v1.0.167

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

React Simple Table

Intention

The table should be as easy as possible to use.

Installation

yarn

yarn add @postadress/react-simple-table

npm

npm install @postadress/react-simple-table

Usage

React Simple Table uses the location for storing filter strings. Therefore it mus be used inside a Router component.

A basic example:

import React, { FC } from 'react';
import { SimpleTable } from '@postadress/react-simple-table';
import { Field } from '@postadress/react-simple-table/dist/table';

export const Component: FC = () => {
  const fields: Field[] = [
    {
      name: 'ID',
      identifier: 'id',
      width: 10,
    },
    {
      name: 'First Name',
      identifier: 'firstName',
    },
    {
      name: 'Last Name',
      identifier: 'lastName',
    },
    {
      name: 'Age',
      identifier: 'age',
      type: 'number'
    },
  ];

  const data = [
    {
        id: 1,
        firstName: 'Johnny',
        lastName: 'Lawrence',
        age: 50,
    },
    {
        id: 2,
        firstName: 'Daniel',
        lastName: 'LaRusso',
        age: 50,
    },
    {
        id: 3,
        firstName: 'Miguel',
        lastName: 'Diaz',
        age: 17,
    },
    {
        id: 4,
        firstName: 'Samantha',
        lastName: 'LaRusso',
        age: 17,
    }
  ];

  return (<SimpleTable fields={fields} data={data} />);
};

The above example will lead to a table like this:

React Simple Table example

Api

Field

Interface for column definitions.

PropertyTypeOptionalDefaultPurposeExample
namestringnoThis is the name of the column and therefore it is shown in the header row.name: 'First name'
identifierstringnoTechnical identifier for the column. The name must not be unique, the identifier must.identifier: 'firstName'
widthnumberyesThe with of the column in px.width: 120
formatterfunctionyesA callback function which is used to render the cell content.(val, name, row) => <>{'#' + val}</>
getSortValuefunctionyesA callback function which is used to sort rows.(val, name, row) => dateToIso(val);
getFilterValuefunctionyesA callback function which is used to filter rows.(val, name, row) => dateToGermanDate(val);
onEditfunctionyesA callback function which is called, when the row is edited.(val, field, row, index) => alert(val);
type'button', 'checkbox', 'color' *yestextHTML5 input types. Used to render edit input fields.type: 'date',
editablebooleanyesfalseIf true, the cell can be edited by double clicking on it.editable: true

* 'button' | 'checkbox' | 'color' | 'date' | 'datetime' | 'email' | 'file' | 'hidden' | 'image' | 'month' | 'number' | 'password' | 'radio' | 'range' | 'reset' | 'search' | 'submit' | 'tel' | 'text' | 'time' | 'url' | 'week'

DatatableProps

Interface to configure the table itself.

PropertyTypeOptionalDefaultPurposeExample
fieldsField[]noThe field definitions to be used by the table.fields: {name: 'name', identifier: 'name'}
dataany[]noThe data to be presented in the table.{name: 'Johnny Lawrence'}, {name: 'Daniel LaRusso'}
showFilterbooleanyesfalseIf true the filter widget above the table is is visible.showFilter: true
hideResultCountbooleanyesfalseIf true the result count above the table is is invisible.hideResultCount: true
identifierstringyes'filter'Used to discriminate different tables on a page. The main purpose is: It is used in the location portion of the URL, to decide, to which table a filter belongs.identifier: 'mainTable'
langstringyes'en'Used for i18n. Currently only English and German is available.lang: 'de'
showDownloadbooleanyesfalseWhen true, a download button will be visible in top of the table.showDownload: true
customDownloadFunction(tableData: any[]) => voidyesCallback function, which will be triggered when clicking the download button (showDownload must be set to true)customDownloadFunction: (tableData: any[]) => apiCall()
pageSizenumberyes1000Amount of rows which will be presented in viewport before rerendering the next chunk. When onFetchAdditionalResults is set, it will be triggered when the amount is reached.pageSize: 100
onFetchAdditionalResults() => voidyesCallback function which will be triggered when the user scolls to the bottom to the table. Uses pageSize.onFetchAdditionalResults: (tableData: any[]) => apiCall()
disableSortingbooleanyesfalseIf true, the cell can be edited by double clicking on it.disableSorting: true
showRowFiltersbooleanyesfalseIf true the row filter inputs will be visible.showRowFilter: true
pageSizenumberyesIf provided, it will be used as the total amount of data instead of the data length.pageSize: 100

You can find a working example on CodeSandbox.

Contributions are welcome!

1.0.165

3 years ago

1.0.164

3 years ago

1.0.167

3 years ago

1.0.166

3 years ago

1.0.161

3 years ago

1.0.163

3 years ago

1.0.162

3 years ago

1.0.160

3 years ago

1.0.154

3 years ago

1.0.153

3 years ago

1.0.156

3 years ago

1.0.155

3 years ago

1.0.158

3 years ago

1.0.157

3 years ago

1.0.159

3 years ago

1.0.143

3 years ago

1.0.142

3 years ago

1.0.145

3 years ago

1.0.144

3 years ago

1.0.141

3 years ago

1.0.140

3 years ago

1.0.147

3 years ago

1.0.146

3 years ago

1.0.149

3 years ago

1.0.148

3 years ago

1.0.132

3 years ago

1.0.131

3 years ago

1.0.134

3 years ago

1.0.133

3 years ago

1.0.139

3 years ago

1.0.136

3 years ago

1.0.135

3 years ago

1.0.138

3 years ago

1.0.137

3 years ago

1.0.150

3 years ago

1.0.152

3 years ago

1.0.151

3 years ago

1.0.130

3 years ago

1.0.101

3 years ago

1.0.100

3 years ago

1.0.107

3 years ago

1.0.106

3 years ago

1.0.109

3 years ago

1.0.108

3 years ago

1.0.103

3 years ago

1.0.102

3 years ago

1.0.105

3 years ago

1.0.104

3 years ago

1.0.121

3 years ago

1.0.120

3 years ago

1.0.123

3 years ago

1.0.122

3 years ago

1.0.129

3 years ago

1.0.128

3 years ago

1.0.125

3 years ago

1.0.124

3 years ago

1.0.127

3 years ago

1.0.126

3 years ago

1.0.110

3 years ago

1.0.112

3 years ago

1.0.111

3 years ago

1.0.118

3 years ago

1.0.117

3 years ago

1.0.119

3 years ago

1.0.114

3 years ago

1.0.113

3 years ago

1.0.116

3 years ago

1.0.115

3 years ago

1.0.99

3 years ago

1.0.98

3 years ago

1.0.97

3 years ago

1.0.66

3 years ago

1.0.65

3 years ago

1.0.69

3 years ago

1.0.68

3 years ago

1.0.67

3 years ago

1.0.73

3 years ago

1.0.72

3 years ago

1.0.71

3 years ago

1.0.70

3 years ago

1.0.77

3 years ago

1.0.76

3 years ago

1.0.75

3 years ago

1.0.74

3 years ago

1.0.79

3 years ago

1.0.78

3 years ago

1.0.80

3 years ago

1.0.84

3 years ago

1.0.83

3 years ago

1.0.82

3 years ago

1.0.81

3 years ago

1.0.88

3 years ago

1.0.87

3 years ago

1.0.86

3 years ago

1.0.85

3 years ago

1.0.89

3 years ago

1.0.91

3 years ago

1.0.90

3 years ago

1.0.95

3 years ago

1.0.94

3 years ago

1.0.93

3 years ago

1.0.92

3 years ago

1.0.96

3 years ago

1.0.62

3 years ago

1.0.61

3 years ago

1.0.60

3 years ago

1.0.64

3 years ago

1.0.63

3 years ago

1.0.44

3 years ago

1.0.48

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.49

3 years ago

1.0.51

3 years ago

1.0.50

3 years ago

1.0.55

3 years ago

1.0.54

3 years ago

1.0.53

3 years ago

1.0.52

3 years ago

1.0.59

3 years ago

1.0.58

3 years ago

1.0.57

3 years ago

1.0.56

3 years ago

1.0.43

3 years ago

1.0.42

3 years ago

1.0.41

3 years ago

1.0.39

3 years ago

1.0.40

3 years ago

1.0.38

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago