# @maximus905/simple-table

> simple table based on bootstrap

Latest version **1.0.0** (published 2020-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @maximus905/simple-table
pnpm add @maximus905/simple-table
yarn add @maximus905/simple-table
bun add @maximus905/simple-table
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-12-16 |
| First published | 2020-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 15 |
| Unpacked size | 4.5 MB |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maximus905 |
| Maintainers | maximus905 |
| Keywords | react-component |

## Links

- npm: https://www.npmjs.com/package/@maximus905/simple-table
- Repository: https://github.com/Maximus905/baseTableComponent
- Homepage: https://github.com/Maximus905/baseTableComponent#readme
- Issues: https://github.com/Maximus905/baseTableComponent/issues
- npm.io page: https://npm.io/package/@maximus905/simple-table

## Dependencies (15)

- [axios](https://npm.io/package/axios.md) ^0.19.2
- [fuse.js](https://npm.io/package/fuse.js.md) ^6.4.1
- [immutable](https://npm.io/package/immutable.md) ^4.0.0-rc.12
- [classnames](https://npm.io/package/classnames.md) ^2.2.6
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [reactstrap](https://npm.io/package/reactstrap.md) ^8.4.1
- [check-types](https://npm.io/package/check-types.md) ^11.1.2
- [react-window](https://npm.io/package/react-window.md) ^1.8.5
- [@emotion/core](https://npm.io/package/@emotion/core.md) ^10.0.28
- [emotion-theming](https://npm.io/package/emotion-theming.md) ^10.0.27
- [react-scrollbar-size](https://npm.io/package/react-scrollbar-size.md) ^2.1.0
- [@maximus905/dropdown-list](https://npm.io/package/@maximus905/dropdown-list.md) ^1.0.0
- [@fortawesome/react-fontawesome](https://npm.io/package/@fortawesome/react-fontawesome.md) ^0.1.9
- [@fortawesome/fontawesome-svg-core](https://npm.io/package/@fortawesome/fontawesome-svg-core.md) ^1.2.27
- [@fortawesome/free-solid-svg-icons](https://npm.io/package/@fortawesome/free-solid-svg-icons.md) ^5.12.1

## Recent versions

- 1.0.0 (latest) — 2020-12-16

## README

# table component

[![Travis][build-badge]][build]
[![npm package][npm-badge]][npm]
[![Coveralls][coveralls-badge]][coveralls]

Simple  Table component

Some of props definition:
* __tableDataLoader__ - async function
  * default loader:
  ```javascript
  const defaultTableDataLoader = async ({url, filters, extFilters, sorting, pagination, dataFieldName, dataCounterFieldName}) => {
      try {
          const res = await axios.get(url, {
              params: {filters, extFilters, sorting, pagination, dataFieldName, dataCounterFieldName}
          })
          if (res.status !== 200 || !Array.isArray(res.data[dataFieldName])) {
              console.log('Error fetching data from server: ', res)
              throw new Error('Error fetching data from server')
          }
          return res.data
      } catch (e) {
          alert(e.toString())
          return []
      }
  }
  ```
* __url__ argument is got from props.tableDataUrl (see below).
 It should return object structure like this:
  ```javascript
  {
      [dataFieldName]: [
          {accessor1: 'value 1'}, {accessor2: 'value 2'},
          {accessor1: 'value n'}, {accessor2: 'value n'}
      ],
      [dataCounterFieldName]: 'numberOfRecords'
  }
  ```
if the field **dataCounterFieldName** isn't presented in response, counter of records and pagination won't be shown in the footer

Default values:
```javascript
    dataFieldName: 'data',
    counterFieldName: 'counter'
```
* __dataFieldName__ - field name for data in the structure above
* __dataCounterFieldName__ - field name of record counter in the structure above. This number will be shown in the footer as a records counter. And this number is also used for calculating pagination parameters. 

Where are used dataFieldName and dataCounterFieldName?

our server should send table data in structure like:
```javascript
{
    [dataFieldName]: [table data],
    [dataCounterFieldName]: number_of_records
}
```
* __filterDataLoader__ - async function fetched data for filters of LIST type
  * default loader:
  ```javascript
  const defaultFilterDataLoader = async ({url, filters, extFilters, accessor, dataFieldName}) => {
      try {
          const res = await axios.get(url, {
              params: {accessor, filters, extFilters, dataFieldName}
          })
          if (res.status !== 200 || !Array.isArray(res.data[dataFieldName])) {
              console.log('invalid data from server: ', res)
              throw new Error('Error fetching filter list from server')
          }
          return res.data[dataFieldName]
      } catch (e) {
          alert(e.toString())
          return []
      }
  }
  ```
 __url__ argument is got from props.filterDataUrl (see below).
 It should return array of ordered values or array of objects, where each object should look like
```javascript
{filterValueName: 'value', filterLabelName: 'label'}
```
. If the function returns simple array, each value is used as value and as label
 * __filterValueName__ - field name of value. This prop is used only if __getFilterList__ function returns array of objects 
* __filterLabelName__ - field name of label. This prop is used only if __getFilterList__ function returns array of objects 
* __tableDataUrl__ - URL for fetching table data.
* __filterDataUrl__ - URL for fetching filter data (it's used only for LIST type of filters).
* __extFilters__ - external filter that can be passed to table and changed onu of table. If __passThrowExtFilter__=== true, this filter will be sent to server as is, but if __passThrowExtFilter__=== false, this filter will be converted as usual table filter. So, to be able to convert as usual table filter it should have structure like this:
  ```javascript
  {
    filterBy: '', // string
    value: [], // array of values
    type: '', // one of available filter types (see below)
    selectAll: true/false // this field is required only for LIST type
  }
  ``` 
* __api__ - usually empty object that will be filled after mounting table by useful methods
  * __api.reload__ update table's data with current settings(filters, sorting etc.)
* __onBeforeRequestData__ (function) is called before loading data from a server (without any arguments). 
* __onAfterSuccessfulRequestData__ (function) is called after successful loading data from a server (without any arguments).
* __onAfterFailedRequestData__ (function) is called after failed loading data from a server (without any arguments).
* __onAfterRequestData__ (function) is called after either successful or failed loading data from a server (without any arguments).
#### Filter types:
* type: EQ, label: '=', filterName: 'равно'},
* type: NE, label: '!=', filterName: 'не равно'},
* type: LT, label: '<', filterName: 'меньше'},
* type: LE, label: '<=', filterName: 'меньше или равно'},
* type: GT, label: '>', filterName: 'больше'},
* type: GE, label: '>=', filterName: 'больше или равно'},
* type: STARTING, label: 'начинается с'},
* type: ENDING, label: 'заканчивается на'},
* type: INCLUDING, label: 'содержит'},
* type: LIST, label: 'список', loadFromServer: true, }

[build-badge]: https://img.shields.io/travis/user/repo/master.png?style=flat-square
[build]: https://travis-ci.org/user/repo

[npm-badge]: https://img.shields.io/npm/v/npm-package.png?style=flat-square
[npm]: https://www.npmjs.org/package/npm-package

[coveralls-badge]: https://img.shields.io/coveralls/user/repo/master.png?style=flat-square
[coveralls]: https://coveralls.io/github/user/repo

---
_Source: https://npm.io/package/@maximus905/simple-table · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
