1.0.8 • Published 12 months ago

react-customize-data-table v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

react-customize-data-table

A React table component designed to display large data with high performance.

Features

  • 🚀High Performance: Turn on virtual scrolling when the amount of data is large
  • 🎨Customization: Simple and flexible API, rich customization capabilities
  • đź’ŽUseful Properties: Support complex functions such as sorting, searching, pagination, fixed header, left/right lock columns, custom operations, etc.

Example

http://localhost:8000

online example: https://haianweifeng.github.io/react-customize-data-table

Install

npm i react-customize-data-table

Development

Install dependencies,

$ npm i

Start the dev server,

$ npm start

Build documentation,

$ npm run docs:build

Run test,

$ npm test

Build library via father,

$ npm run compile

Usage

import Table from 'react-customize-data-table';

ReactDOM.render(<Table />, container);

API

Table

PropertyDescriptionTypeDefault
classNameCustom class names for tablestring-
styleCustom style for tableReact.CSSProperties-
dataSourceData record array to be displayedobject[]-
columnsColumns of tableColumnsType<T>-
rowKeyRow's unique key, the default value is keystring | ((row: T) => string | number)key
stripedShow stripe or not.booleanfalse
borderedWhether to show all table bordersbooleanfalse
loadingLoading status of tableboolean | React.ReactNodefalse
showHeaderWhether to show table headerbooleantrue
sizeSize of tabledefault | small | largedefault
rowClassNameRow's className(record: T, index: number) => string-
rowStyleRow's style((record: T, index: number) => React.CSSProperties) | React.CSSProperties-
cellClassNamecustom class names for a cell((column: ColumnType<T>, rowIndex: number, colIndex: number) => string) | string-
cellStylecustom style for a cell((column: ColumnType<T>, rowIndex: number, colIndex: number) => React.CSSProperties) | React.CSSProperties-
headerCellClassNamecustom class names for a cell in table header((column: ColumnType<T> | ColumnGroupType<T>, rowIndex: number, colIndex: number) => string) | string-
headerCellStylecustom style for a cell in table header((column: ColumnType<T> | ColumnGroupType<T>, rowIndex: number, colIndex: number) => React.CSSProperties) | React.CSSProperties-
headerRowClassNamecustom class names for a row in table header((rowIndex: number) => string) | string-
headerRowStylecustom style for a row in table header((rowIndex: number) => React.CSSProperties) | React.CSSProperties-
onHeaderRowEventsSet events on per header row(rowIndex: number) => object-
onHeaderCellEventsSet events on per header cell(column: ColumnType<T> | ColumnGroupType<T>, rowIndex: number) => object-
onRowEventsSet events on per row(record: T, rowIndex: number) => object-
onCellEventsSet events on per cell(record: T, rowIndex: number) => object-
paginationConfig of paginationPaginationProps-
emptyDisplayed text when data is emptystring | React.ReactNode-
localeThe i18n textLocalType-
rowHeightThe expected height of the table rownumber-
renderMaxRowsMaximum number of rows per rendernumber-
widthThe width of the tablenumber-
heightThe height of the table. Unit: px / When this prop is set, if the content height is larger then the set value, the header will be fixed at the top.number-
virtualizedWhether to enable the virtual listboolean-
onScrollThe callback function after scrolling.(x: number, y: number) => void-
onColumnResizecolumns resize callback(newWidth: number, oldWidth: number, column: ColumnType<T>, event: Event) => void-
rowSelectionRow selection, configobject-
onSortSort event(sortResult: { column: ColumnType<T>, order: asc | desc | null, field: string | undefined }) => void-
onFilterFilter event(filterInfo: Record<React.Key, React.Key[]>) => void-
expandableConfig expandable content, configobject-
treePropsConfigure tree data properties, configobject-
summaryRender footer{ render: () => React.ReactNode; colSpan?: number; rowSpan?: number }-

Column

One of the Table columns prop for describing the table's columns, Column has the same API.

PropertyDescriptionTypeDefault
typeSet column typeexpand | checkbox | radio | defaultdefault
alignThe specify which way that column is alignedleft | center | rightleft
classNameThe className of this columnstring-
dataIndexDisplay field of the data recordstring-
keyUnique key of this column, you can ignore this prop if you've set a unique dataIndexstring-
fixedColumn fixed If multiple adjacent columns need to be locked, you only need to specify the outermost column, and it will take effect with horizontal scrollingleft | right-
renderRenderer of the table cell. The return value should be a ReactNode(text: any, record: T, index: number) => React.ReactNode-
titleTitle of this columnReact.ReactNode-
widthWidth of this columnnumber | string-
maxWidthMaximum column widthnumber | string-
minWidthMinimum column widthnumber | string-
ellipsisThe ellipsis cell contentboolean | { tooltip: boolean; tooltipTheme?: dark | light; renderTooltip?: (trigger: React.ReactNode, tip: React.ReactNode) => React.ReactNode;}-
colSpanThe header columns are merged, when set to 0, no renderingnumber-
resizableWhether to allow drag and drop to adjust the width The border attribute needs to be enabled, and for multi-level headers only supports drag and drop to adjust the width of the last level headerboolean-
onCellSet props on per cell(record: T, rowIndex: number) => { colSpan?: number; rowSpan?: number }-
defaultSortOrderDefault order of sorted valuesasc | desc-
sortOrderOrder of sorted valuesasc | desc | null-
sorterSort function((rowA: T, rowB: T) => number) | { compare: (rowA: T, rowB: T) => number; weight: number; }-
renderSorterCustomize sort icons(params: { activeAsc: boolean; activeDesc: boolean; triggerAsc: (event: React.MouseEvent) => void; triggerDesc: (event: React.MouseEvent) => void; }) => React.ReactNode-
defaultFilteredValueDefault filtered valuesReact.Key[]-
filteredValueControlled filtered valueReact.Key[]-
filterMultipleWhether multiple filters can be selectedboolean-
filterIconCustomized filter icon(filtered: boolean) => React.ReactNode-
filterSearchWhether to be searchable for filter menu((value: string, record: FilterMenus) => boolean) | boolean-
filtersFilter menu config{ label: string; value: string }[]-
filterMethodFunction that determines if the row is displayed when filtered(value: React.Key, record: T) => boolean-

ColumnGroup

Refer to config of column, but ignore dataIndex and type attribute, add children attribute, children is the collection of column configuration attributes.

expandable

Properties for expandable.

PropertyDescriptionTypeDefault
columnTitleSet the title of the expand columnReact.ReactNode-
columnWidthSet the width of the expand columnstring | number-
expandedRowRenderExpanded container render for each row(record: T, index: number, expanded: boolean) => React.ReactNode-
expandedRowClassNameExpanded row's className(record: T, index: number) => string-
rowExpandableEnable row can be expandable(record: T) => boolean-
defaultExpandAllRowsExpand all rows initiallybooleanfalse
defaultExpandedRowKeysInitial expanded row keysstring[] | number[]-
expandedRowKeysCurrent expanded row keysstring[] | number[]-
expandIconCustomize row expand Icon(record: T, expanded: boolean, onExpand?: (expanded: boolean, record: T) => void) => React.ReactNode-
onExpandCallback executed when the row expand icon is clicked(expanded: boolean, record: T) => void-

TreeExpandable

Configuration of tree functions.

PropertyDescriptionTypeDefault
indentSizeindent of each levelnumber15
treeColumnsNameThe name of the column where the icon is expandedstring-
defaultExpandAllRowsExpand all rows initiallybooleanfalse
defaultExpandedRowKeysInitial expanded row keysstring[] | number[]-
expandedRowKeysCurrent expanded row keysstring[] | number[]-
expandIconCustomize row expand Icon(record: T, expanded: boolean, onExpand?: (expanded: boolean, record: T) => void) => React.ReactNode-
onExpandCallback executed when the row expand icon is clicked(expanded: boolean, record: T) => void-

rowSelection

Properties for row selection.

PropertyDescriptionTypeDefault
columnTitleSet the title of the selection columnReact.ReactNode-
columnWidthSet the width of the selection columnstring | number44px
getCheckboxPropsGet Checkbox or Radio props(record: T) => any-
renderCellRenderer of the table cell. Same as render in column(checked: boolean, record: T, index: number, originNode: React.ReactNode) => React.ReactNode-
selectedRowKeysControlled selected row keysstring[] | number[]-
defaultSelectedRowKeysInitial selected row keysstring[] | number[]-
typecheckbox or radiocheckbox | radiocheckbox
onChangeCallback executed when selected rows change(selectedRowKeys: (string | number)[], selectedRows: T[]) => void-
onSelectCallback executed when select/deselect one row(record: T, selected: boolean, selectedRows: T[], nativeEvent: Event) => void-
onSelectAllCallback executed when select/deselect all rows(selected: boolean, selectedRows: T[], changeRows: T[]) => void-

LocalType

The i18n text for filter。

PropertyDescriptionTypeDefault
filterSearchPlaceholderFilter Search Box Promptsstring'Search in filters'
filterEmptyTextPrompt copy when there is no filter menustring'No filters'
filterResultfilter search resultsstring'Not Found'
filterConfirmfilter OK buttonstring'Filter'
filterResetfilter reset buttonstring'Reset'