1.1.80 • Published 2 years ago

@o2xp/react-datatable v1.1.80

Weekly downloads
324
License
MIT
Repository
github
Last release
2 years ago

@o2xp/react-datatable

Build Status Code coverage Maintainability License: MIT Version code style: prettier

@o2xp/react-datatable is a modulable component to render data in a table with some nice features !

See a show case just here.

Table of Contents

Getting Started

Installing

$ npm i --save @o2xp/react-datatable

In your file :

// ES6
import {Datatable} from "@o2xp/react-datatable";
import React, { Component } from "react";

// Basic Example
let options  = {
    keyColumn: 'id',
    data: {
        columns: [ 
            {
                id: "id",
                label: "id",
                colSize: "80px"
            },
            {
                id: "name",
                label: "name",
                colSize: "150px"
            },
            {
                id: "age",
                label: "age",
                colSize: "50px"
            },
        ],
        rows: [
            {
                id: "50cf",
                age: 28,
                name: "Kerr Mayo"
            },
            {
                id: "209",
                age: 34,
                name: "Freda Bowman"
            },
            {
                id: "2dd81ef",
                age: 14,
                name: "Becky Lawrence"
            }
        ],
    }
}

class App extends Component {
    render() {
        return <Datatable options={options} />;
    }
}

export default App;

Attention : the column id "o2xpActions" is reserved. Using it can result of unexpected behaviours.

Live implementation

To go further check all examples

Prop Types

Datatable Properties

PropertyTypeRequired?Description
optionsobjectyesAn object that all the options to render the datatable. See Options Properties.
actionsfunctionnoFunction that take as parameter {type, payload}, where type is the action performed (save, delete etc..) and payload the data needed to perform the action. See advanced example.
refreshRowsfunctionnoFunction that return an an array of objects where each object is defined by the columns identifier as key and the value. See advanced example.
forceRerenderbooleannoDo you want to rerender the component on route change or keep the state ?
strippedbooleannoDo you want stripped rows ?
CustomTableBodyRowfunctionnoFunction that take { row, columnsOrder, rowIndex, columnSizeMultiplier, height } and return a react html element. See body row example.
CustomTableBodyCellfunctionnoFunction that take { cellVal, column, rowId } and return a react html element. See body cell example.
CustomTableHeaderRowfunctionnoFunction that take { columnsOrder, columnSizeMultiplier } and return a react html element. See header row example.
CustomTableHeaderCellfunctionnoFunction that take { column } and return a react html element. See header cell example.
customDataTypesarraynoobject that return an array of object with datatypes and react html element. See datatypes cell example.
textobjectnoAn object with text to override. See text override.
themeobjectnoSee theming.

Options Properties

PropertyTypeRequired?DefaultDescription
titlestringno" "Title of the datatable.
textobjectnoUn object with key taking a string as value. Click here to have more information.
dimensions .datatable .widthstringno"100vw"Width of the the Datatable. (in vw / px / %)
dimensions .datatable .heightstringno"300px"Height of the Datatable. (in vh / px / %)
dimensions .row .heightstringno"33px"Height of each row of the Datatable. (in px) Minimum 33px.
keyColumnstringyes/Name of the column that has unique value and allows to identify a row.
currentScreenstringno/Name of the screen that will used to differentiate created presets. If you put the same string for 2 datatables, it will show the same created presets.
fontstringno"Roboto"Name of the font you are using. It allows the datatable to calculate the overlapping of cells.
data .columnsarray of objectyes/An array of objects where each object is defined by this keys. Click here to have more information.
data .rowsarray of objectyes/An array of objects where each object is defined by the columns identifier as key and the value. Click here to have more information.
features .canEditbooleannofalseIf the user can edit the rows.
features .canEditRow(row) => booleanno() => trueGiving row as parameter and expecting a boolean as result. Do determine if a row is editable or not.
features .canGlobalEditbooleannofalseIf the user can turn in edit mode all the rows.
features .canPrintbooleannofalseIf you want stripped rows.
features .canDownloadbooleannofalseIf the user can download the data.
features .canCreatePresetbooleannofalseIf the user can create preset(list of columns to display). The created preset will be stored in the local storage.
features .canSearchbooleannofalseIf the user can filter the data by text through a search input globally.
features .canFilterbooleannofalseIf the user can filter the data by text through a search input based on different columns.
features .canRefreshRowsbooleannofalseIf the user can click to refresh the rows.
features .canOrderColumnsbooleanfalsenoIf the user can select the columns to display.
features .canSelectRowbooleanfalsenoIf the user can select rows.
features .canDuplicatebooleanfalsenoIf the user can duplicate row.
features .isUpdatingRowsbooleanfalsenoIf you are updating rows on your side.
features .canSaveUserConfigurationbooleannofalseIf the user can save his columns configuration. (order and which one is displayed)
features .userConfiguration .columnsOrderarray of stringsno An array of strings where the strings are the column identifier. Datatable will be rendered only with the columns present in the array.
features .userConfiguration .copyToClipboardbooleannofalseIf true, when the user click on cell it will copy the value in the clipboard.
features .rowsPerPage .availablearray of number and stringno10, 25, 50, 100, "All"An array with the numbers of rows per page you want available.
features .rowsPerPage .selectednumber or stringno"All"The number of rows per page selected by default.
features .additionalIconsarray of objectno If you want to add icon which trigger a function. Click here to have more information.
features .columnsPresetsToDisplayarray of objectno If you want to add predefined presets in the Display by presets Tab. Click here to have more information.
features .additionalIconsarray of objectno If you want to add icon which trigger a function. Click here to have more information.
features .selection .selectionIconsarray of objectno If you want to add icon which execute a function with the rows selected. Click here to have more information.

Columns Props

Columns is an array of object construct with these keys :

PropertyTypeRequired?Description
idstringyesId of the column (need to be unique).
labelstringyesLabel of the column.
colSizenumberyesSize of the column (needs to be in px).
editablebooleannoIf the each value of row corresponding to the column is editable or not.
dataTypestringnoPossible values: "number", "text", "boolean", "date", "time", "dateTime". For more type, see override section.
inputTypestringnoPossible values: "input", "boolean", "select", "datePicker", "timePicker", "dateTimePicker"
dateFormatInstringyes (only if datatype === "date" || "time" || "dateTime")Format of the date.
dateFormatOutstringyes (only if datatype === "date" || "time" || "dateTime")Format you want to display of the date.
valuesarrayyes (only if inputType === "select")Possible values displayed in the select.
valueVerificationfunctionnoIf you want to verify value on save. You need to provide a function which take a parameter (the new value) and return and object in this format {error: boolean, message: string}
maskarray of regexnoWorks only with inputType === input. To build regex see react-text-mask

Rows Props

Rows is an array of object where each object is defined by the columns identifier as key and the value. You can add this key for edit purpose :

PropertyTypeRequired?Description
editableIdArraynoId of the columns where fields should be editable.

Columns Presets To Display Props

Columns Presets to display is an array of object construct with these keys :

PropertyTypeRequired?Description
presetNamestringyesDescription of the preset.This string will be shown on screen.
columnsToShowarray of stringyesList of existing columns to show
isActivebooleanyesIf the box should be tick
typestringyesMust be "predefinedPreset"

Additional Actions Props

Additional actions is an array of object construct with these keys :

PropertyTypeRequired?Description
titlestringyesDescription of the button. The text will be displayed on hovering the icon
iconComponentyesUse @material-ui/icons to provide an icon to display.
onClickfunctionyesA function that take a row as parameter. The function will be triggered on click.

Additional Icons Props

Additional icons is an array of object construct with these keys :

PropertyTypeRequired?Description
titlestringyesDescription of the button. The text will be displayed on hovering the icon
iconComponentyesUse @material-ui/icons to provide an icon to display.
onClickfunctionyesA function that doesn't take parameter. The function will be triggered on click.

Additional Selection Icons Props

Additional selection icons is an array of object construct with these keys :

PropertyTypeRequired?Description
titlestringyesDescription of the button. The text will be displayed on hovering the icon
iconComponentyesUse @material-ui/icons to provide an icon to display.
onClickfunctionyesA function that takes a parameter (the selected rows). . The function will be triggered on click.

Text override

PropertyTypeRequired?Default value
searchstringno"Toggle"
searchPlaceholderstringno"Search.."
editstringno"Edit"
clearstringno"Clear"
savestringno"Save"
deletestringno"Delete"
confirmDeletestringno"Confirm delete"
cancelDeletestringno"Cancel delete"
downloadstringno"Download data"
downloadTitlestringno"Download Data"
downloadDescriptionstringno"Data will be exported in"
downloadSelectedRowsstringno"Selected rows"
downloadCurrentRowsstringno"Rows of current page"
downloadAllRowsstringno"All rows"
displaystringno"Display columns"
refreshstringno"Refresh"
configurationstringno"Configuration"
configurationTitlestringno"User Configuration"
configurationCopystringno"Save cell's content to clipboard on click"
configurationColumnstringno"Do you want to save the configuration of the columns and copy to clipboard feature ?"
configurationResetstringno"Reset"
configurationSavestringno"Save"
createstringno"Create"
createTitlestringno"Create a new row"
createCancelstringno"Cancel"
createSubmitstringno"Create"
duplicatestringno"Duplicate"
printstringno"Print"
orderBystringno"Order by"
dragstringno"Drag"
paginationRowsstringno"Rows"
paginationPagestringno"Page"
createPresetTitlestringno"Create New Preset"
createPresetDescriptionstringno"Select the columns to save in the preset"
createPresetTooltipTextstringno"Create a new preset"
createPresetNamingPlaceholderstringno"Preset name"
createPresetCancelBtnstringno"Cancel"
createPresetCreateBtnstringno"Create"

Overriding

Because we want flexibility for our users we decide to leave a lot of possibility to users. So what can you override ?

Contributing

Do you want to contribute to this project ? Great ! You can start by reading our contributing guide.

Build With

  • React - A JavaScript library for building user interfaces
  • Redux - Redux is a predictable state container for JavaScript apps
  • Material-ui - React components that implement Google's Material Design
  • Webpack - A bundler for javascript and friends. Packs many modules into a few bundled assets.
  • Babel - Babel is a tool that helps you write code in the latest version of JavaScript. When your supported environments don't support certain features natively, Babel will help you compile those features down to a supported version.
  • Storybook - Storybook is an open source tool for developing UI components in isolation for React, Vue, and Angular. It makes building stunning UIs organized and efficient.
  • Eslint - ESLint is an open source project originally created by Nicholas C. Zakas in June 2013. Its goal is to provide a pluggable linting utility for JavaScript.
  • Jest - Jest is a delightful JavaScript Testing Framework with a focus on simplicity.
  • Enzyme - Enzyme is a JavaScript Testing utility for React that makes it easier to test your React Components' output. You can also manipulate, traverse, and in some ways simulate runtime given the output.
  • Prettier - Prettier is an opinionated code formatter.
  • Husky - Husky can prevent bad git commit, git push and more 🐶 woof!

Contributors

1.1.79

2 years ago

1.1.80

2 years ago

1.1.70

2 years ago

1.1.74

2 years ago

1.1.73

2 years ago

1.1.72

2 years ago

1.1.71

2 years ago

1.1.78

2 years ago

1.1.77

2 years ago

1.1.76

2 years ago

1.1.75

2 years ago

1.1.69

2 years ago

2.0.0-beta.2

3 years ago

1.1.67

3 years ago

1.1.68

3 years ago

2.0.0-beta.1

3 years ago

1.1.66

3 years ago

1.1.65-beta.1

3 years ago

1.1.64

3 years ago

1.1.63

4 years ago

1.1.62

4 years ago

1.1.61

4 years ago

1.1.60

4 years ago

1.1.59

4 years ago

1.1.58

4 years ago

1.1.57

4 years ago

1.1.56

4 years ago

1.1.55

4 years ago

1.1.54

4 years ago

1.1.53

4 years ago

1.1.52

4 years ago

1.1.51

4 years ago

1.1.49

4 years ago

1.1.48

4 years ago

1.1.47

4 years ago

1.1.46

4 years ago

1.1.41

4 years ago

1.1.44

4 years ago

1.1.43

4 years ago

1.1.42

4 years ago

1.1.40

4 years ago

1.1.38

4 years ago

1.1.39

4 years ago

1.1.37

4 years ago

1.1.36

4 years ago

1.1.35

4 years ago

1.1.34

4 years ago

1.1.33

4 years ago

1.1.32

4 years ago

1.1.31

4 years ago

1.1.30

4 years ago

1.1.29

4 years ago

1.1.28

4 years ago

1.1.27

4 years ago

1.1.26

4 years ago

1.1.25

4 years ago

1.1.24

4 years ago

1.1.23

4 years ago

1.1.22

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago