1.0.8 • Published 4 months ago

react-datatable-responsive v1.0.8

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

React DataTable Responsive

NPM Downloads npm package minimized gzipped size NPM Version

react-datatable-responsive

It's a datatable component on React. It comes with features like filtering, search, view/hide columns, export to excel file, printing, sorting, selectable rows, pagination, and responsible for mobile/tablet device. On top of the ability to put component, textbox, checkbox, button, img, ... in cells.

Features:

  • filtering
  • search
  • view/hide columns
  • export to excel file
  • printing
  • sorting
  • selectable rows
  • pagination
  • responsible for mobile/tablet
  • resizable columns
  • component, textbox, checkbox, button, img, and ... in cells

component

Table of contents

Install

npm i react-datatable-responsive

Usage

simple table

import ReactDataTable from 'react-datatable-responsive';
import { ColumnType } from 'react-datatable-responsive';

const columns: ColumnType[] = [
  { field: { title: 'title' }, label: 'Title' },
  { field: { title: 'price' }, label: 'Price' },
  { field: { title: 'category' }, label: 'Category' },
]

const data = [
  { title: "Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops", price: 109.95, category: "men's clothing"},
  { title: "Mens Casual Premium Slim Fit T-Shirts ", price: 22.3, category: "men's clothing"},
  { title: "Mens Cotton Jacket", price: 55.99, category: "men's clothing"},
]

export default function Example() {
  return (
    <ReactDataTable rows={data} columns={columns} />
  )
}

custemized columns

import ReactDataTable from 'react-datatable-responsive';
import { ColumnType } from 'react-datatable-responsive';

const columns: ColumnType[] = [
  { field: { title: 'id' }, label: 'ID', options: { display: false } },
  { field: { title: 'title' }, label: 'Title', options: { sort: true } },
  { field: { title: 'price' }, label: 'Price', options: { filter: false, sort: true } },
  { field: { title: 'category' }, label: 'Category', options: { search: false } },
]

const data = [
  { id:1, title: "Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops", price: 109.95, category: "men's clothing"},
  { id:2, title: "Mens Casual Premium Slim Fit T-Shirts ", price: 22.3, category: "men's clothing"},
  { id:3, title: "Mens Cotton Jacket", price: 55.99, category: "men's clothing"},
]

export default function Example(): React.JSX.Element {
  return (
    <ReactDataTable rows={data} columns={columns} />
  )
}

API

ReactDataTable

The component accepts the following props:

NameTypeDescription
directionlrt | rtl | inheritDirection used to describe direction of table.
columnsarrayColumns used to describe table. Must be either an array of simple strings or objects describing a column. (This field is required)
rowsarrayRows used to describe table. Must be either an array containing objects of key/value pairs. (This field is required)
optionsobjectOptions used to describe table.

Table Options

NameTypeDefaultDescription
cellsobjectUser provided items in cells. Example
colorobjectUser provided colors to customized table. Example
downloadbooleantrueShow/hide download icon from toolbar. Possible values:true: Button is visible and clickable.false: Button is not visible.
filterbooleantrueShow/hide filter icon from toolbar. Possible values:true: Button is visiable and clickable.false: Button is not visible.
onRowClickfunctionCallback function that triggers when a row is clicked. function(rowData: any) => void
onRowsDeletefunctionCallback function that triggers when row(s) are deleted. function(rowsDeleted: any[]) => void
paginationbooleantrueShow/hide pagination.
printbooleantrueShow/hide print icon from toolbar. Possible values:true: Button is visiable and clickable.false: Button is not visible.
resizableColumnsbooleantrueEnable/disable resizable columns.
responsivebooleantrueEnable/disable responsive table.
rowsPerPagenumber10Number of rows allowed per page.
rowsPerPageOptionsarray5,10,20,50,100Options to provide in pagination for number of rows a user can select.
searchbooleantrueShow/hide search icon from toolbar. Possible values:true: Button is visiable and clickable.false: Button is not visible.
searchPlaceholderstringSearch text placeholder.
selectableRowsHideCheckboxesbooleanfalseHides the checkboxes that appear when selectableRows is set to "multiple" or "single". Can provide a more custom UX, especially when paired with selectableRowsOnClick.
textLabelsobjectUser provided labels to localize text.
viewColumnsbooleantrueShow/hide viewColumns icon from toolbar. Possible values:true: Button is visiable and clickable.false: Button is not visible.

CSS Classes

These class names are useful for styling with CSS. They are applied to the

NameDescription
rdtcell-inputStyles applied to the input in cells
rdtcell-textareaStyles applied to the textarea in cells
rdtcell-imageStyles applied to the image in cells
rdtcell-checkboxStyles applied to the checkbox in cells
rdtcell-textStyles applied to the text in cells
rdtcell-progressStyles applied to the progress in cells
rdtcell-selectStyles applied to the to select in cells
rdtcell-select__optionStyles applied to options in select
rdtcell-buttonStyles applied to the button in cells
rdtfilterStyles applied to the filter box
rdtfilter__titleStyles applied to the title of the filter box
rdtfilter-itemStyles applied to the filter items box
rdtfilter-columnStyles applied to the columns select tag
rdtfilter-column__optionStyles applied to options of the columns select tag
rdtfilter-conditionStyles applied to the conditions select tag
rdtfilter-condition__optionStyles applied to options of conditions select tag
rdtfilter-item__textStyles applied to the input on the filter box
rdtfilter__addStyles applied to the add button on the filter box
rdtfilter-listStyles applied to the filter list box
rdtfilter-list__liStyles applied to the filter list item
rdtfilter-list__removeStyles applied to the remove button on filter list item
rdtmenu-mainStyles applied to the menu box
rdtmenu-selectStyles applied to the select menu box
rdtmenu-titleStyles applied to the caption table
rdtpaginationStyles applied to the pagination box
rdtpagination-pagesStyles applied to the number pagination box
rdtpagination-pages__noStyles applied to the number pagination
rdtpagination-pages__no--selectStyles applied to the current page no
rdtpagination-per-pageStyles applied to the per page select
rdtsearchStyles applied to the search box
rdtsearch__inputStyles applied to the input on search box
rdtsearch__closeStyles applied to the close button on search box
rdtshowcolumnStyles applied to the show column box
rdtshowcolumn__titleStyles applied to the caption show column box
rdtshowcolumn__liStyles applied to the list columns on show column box
rdtshowcolumn__labelStyles applied to the label list columns on show column box
rdttable-nodataStyles applied to the no data alert
rdttableStyles applied to the table
rdttable-header__labelStyles applied to the header label

Customize Columns

On each column object, you have the ability to customize columns to your liking with the 'options' property. Example:

const columns = [
 {
  name: "Name",
  options: {
   filter: true,
   sort: false,
   ...
  }
 },
 ...
];

Column:

NameTypeDescription
fieldobjectTitle of column (This field is required) and function to handle cell event
labelstringColumn Header Name (This field is required)
kindinput/textbox | input/date | input/datetime-local | input/number | input/file | input/password | textarea | button | image | boolean | select | progress | component,kind of column
optionsobjectOptions for customizing column
eventHandlerHeaderfunctionfunction to handle column event

Column Options:

NameTypeDefaultDescription
componentfunctionFunction that returns a React component. Used to display data within all table cells of a given column. Example
displaybooleantrueDisplay column in table. Possible values:true: Column is visible and toggleable via the View Columns popover in the Toolbar.false: Column is not visible but can be made visible via the View Columns popover in the Toolbar. Example
filterbooleantrueDisplay column in filter list.Example
searchbooleantrueExclude/include column from search results.Example
sortbooleanfalseEnable/disable sorting on column.Example

Options

Change default options

const defaultOptions {
  color: {
    color: '#000',
    backgroundColor: '#fff',
    borderColor: '#ddd'
  },
  download: true,
  filter: true,
  print: true,
  search: true,
  viewColumns: true,
  pagination: true,
  resizableColumns: true,
  responsive: true,
  rowsPerPage: 10,
  rowsPerPageOptions: [5, 10, 20, 50, 100],
  searchPlaceholder: '',
  selectableRowsHideCheckboxes: false,
  cells: {
    imageWidth: 60,
  },
  textLabels: {
    body: {
      title: '',
      noMatch: "Sorry, no data found",
      toolTip: "Sort",
    },
    ...
  }
}

License

The files included in this repository are licensed under the MIT license.

1.0.8

4 months ago

1.0.7

4 months ago

1.0.6

4 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago