0.4.0 • Published 3 years ago

mui-row-select-table v0.4.0

Weekly downloads
274
License
MIT
Repository
-
Last release
3 years ago

Introduction

A Component for displaying large lists of tabular data from an external API.

Installation

yarn add mui-row-select-table

Code Example

Component

import React from 'react'
import RowSelectTable from 'mui-row-select-table'

const column = (name, headerCellContent, other = {}) => ({
  name,
  headerCellContent,
  sortable: true,
  ...other,
})

const results = [
  { id: 0, first_name: 'Leia', last_name: 'Skywalker', home_planet: 'Naboo' },
  { id: 1, first_name: 'Darth', last_name: 'Vader', home_planet: 'Tatooine' },
  {
    id: 2,
    first_name: 'Luke',
    last_name: 'Skywalker',
    home_planet: 'Tatooine',
  },
  { id: 3, first_name: 'Han', last_name: 'Solo', home_planet: 'Unknown' },
  { id: 4, first_name: 'Rey', last_name: '', home_planet: 'Jakku' },
  { id: 5, first_name: 'Kylo', last_name: 'Ren', home_planet: 'Unknown' },
]

const renderAction = () => <i className='material-icons'>remove_red_eye</i>

const getColumnMetadata = () => [
  column('first_name', 'First Name', {}),
  column('last_name', 'Last Name', {}),
  column('home_planet', 'Home Planet', {}),
]

const RowSelectTableExample = () => (
  <RowSelectTable
    columnMetadata={getColumnMetadata()}
    getRowId={(rowData) => rowData.id}
    noDataMessage={'No results found.'}
    setPage={() => {}}
    onRowClick={(rowData, e) => console.log('Row Clicked')}
    results={results}
    isLoading={false}
    changeSort={() => {}}
    setFilter={() => {}}
    maxPage={2}
    pageSize={20}
    currentPage={0}
    pageSizeOptions={[20, 40, 100]}
    showSortableColumns={false}
    stickyHeader={true}
  />
)

export default RowSelectTableExample

Actions File

import { getActions } from 'mui-row-select-table'

// Actions can be used to dispatch to Redux on the respective events.
const {
  ready,
  load,
  clear,
  failed,
  setPage,
  changeSort,
  setFilter,
} = getActions('componentName')

Reducers File

import { getReducer } from 'mui-row-select-table'

const componentReducer = (state = {}, action ) => {
	default:
		return state
}

export default getReducer(componentReducer, 'componentName', 20, '')

Props

ParamTypeDescription
propsObject
props.resultsArray.<Object>The data used to populate the rows.
props.columnMetadataArray.<ColumnMetadataObject>Information about how to display each column.
props.getRowIdfunctionFor helping React generate a unique key for each row. This function is called once with each object in props.results.
props.onRowClickfunctionA function that is called with an object from props.results when the corresponding row is clicked (or when the Enter is pressed while selected).
props.changeSortfunctionTakes a sortColumn and sortAscending value as parameters--called when a sortable column's header is clicked.
props.setPagefunctionTakes an object with page property (and optionally, pageSize) to change the currentPage and pageSize props.
props.maxPagenumberThe last available page in your results. (For pagination in footer.)
props.pageSizenumberThe number of rows per page. (For pagination in footer.)
props.pageSizeOptionsArray.<number>The different options the user should be able to set for pageSize. (For pagination in footer)
props.currentPagenumberThe current page. (For pagination in footer)
props.isLoadingboolWhether or not to display a spinner. Set this value to false when your AJAX request resolves.
props.sortColumnstringThe column currently being used to sort the results. (For sort icon in header.)
props.sortAscendingboolTrue for ascending, false for descending. (For sort icon in header)
props.noDataMessagefunctionA function that returns a component to be displayed when there is no data available. Should be customised from Parent.
props.footerLabelsObjectObject containing footer labels that are displayed in the Footer Section.
props.rowSelectionEnabledboolTrue if RowSelction is enabled, false if RowSelection is not required
props.onSelectAllRowsfunctionA function that is called when selectAllRows checkbox is clicked. Mandatory when rowSelectionEnabled is true
props.onSelectRowfunctionA function that is called when a row is selected by clicking checkbox. Mandatory when rowSelectionEnabled is true
props.isRowSelectedfunctionA function that is called for every row to indicate if the row is selected or not. Mandatory when rowSelectionEnabled is true
props.isAllRowsSelectedboolTrue if all rows are selected. False if all rows are not selected. Mandatory when rowSelectionEnabled is true
props.showSortableColumnsboolOptional prop that allows user to hide default icon for sortable icons. Defaulted to true. Pass false to hide icon
props.stickyHeaderboolOptional prop that controls whether the header of the table is sticky when scrolling. Stickiness will cause the header to stay at the top even when scrolling past
props.stickyFooterboolOptional prop that controls whether the Footer of the table is sticky when scrolling. Stickiness will cause the header to stay at the top even when scrolling past

getActions('ComponentName') returns to you set of Actions that are component specific and allow you to dispatch unique actions and have multiple RowSelectTables throughout the application.

getReducer(componentReducer, componentName, initalPageSize, initialSortColumn )

RowSelectTable~ColumnMetadataObject

Configuration for your columns.

Kind: inner typedef of RowSelectTable Properties

NameTypeDefaultDescription
columnNamestringA key that matches a key in your props.results objects.
headerCellContentstring | number | React.ElementThe content of this column's header cell.
displayfunction(val) => valAn optional function to transform your data in results before displaying it in the table. Should return a valid React node.
sortableboolfalseWhether to allow sorting by clicking the column header.

Contributions

Contributions are welcome, create a Pull Request for any improvements/fixes.

0.4.0

3 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

1.0.0-alphha.1

4 years ago

1.0.0-alphha.0

4 years ago

0.3.4-alpha.0

4 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.0

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago