# @avezen/react-auto-table

> [![npm (scoped)](https://img.shields.io/npm/v/@avezen/react-auto-table.svg)](https://www.npmjs.com/package/@avezen/react-auto-table) [![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/@avezen/react-auto-table.svg)](https://www.npmjs.c

Latest version **1.0.4** (published 2020-04-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install @avezen/react-auto-table
pnpm add @avezen/react-auto-table
yarn add @avezen/react-auto-table
bun add @avezen/react-auto-table
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-04-28 |
| First published | 2020-04-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 115.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | avezen |
| Maintainers | avezen |

## Links

- npm: https://www.npmjs.com/package/@avezen/react-auto-table
- npm.io page: https://npm.io/package/@avezen/react-auto-table

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^16.12.0
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2

## Recent versions

- 1.0.4 (latest) — 2020-04-28
- 1.0.3 — 2020-04-13
- 1.0.2 — 2020-04-13
- 1.0.1 — 2020-04-13
- 1.0.0 — 2020-04-13

## README

# @avezen/react-auto-table

[![npm (scoped)](https://img.shields.io/npm/v/@avezen/react-auto-table.svg)](https://www.npmjs.com/package/@avezen/react-auto-table)
[![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/@avezen/react-auto-table.svg)](https://www.npmjs.com/package/@avezen/react-auto-table)

Removes all spaces from a string.

## Install

```
$ npm install @avezen/react-auto-table
```

## Usage

```js
import React, {Component} from 'react';
import {fetchRequests, fetchRequestsByValue} from "../../service/FakeApiService";
import RequestsTable from "@avezen/react-auto-table";

const colWidths = [
    140,
    80,
    110,
    200,
    120,
    80,
    140,
    100,
    70,
    60,
    70
];

class RequestsTableContainer extends Component {
    state = {
        requests: [],
        currentPage: 1,
        pages: 0,
        search: '',
        sortBy: 'Id',
        sortDirection: 1,
        isFetching: false,
        error: ''
    };

    componentDidMount() {
        this.getRequests();
    }

    render() {
        const { requests, currentPage, pages, search, sortBy, sortDirection, isFetching, error } = this.state;
        return (
            <RequestsTable
                data={requests}
                currentPage={currentPage}
                setCurrentPage={this.setPage}
                pages={pages}
                search={search}
                setSearch={this.setSearch}
                sortBy={sortBy}
                setSortBy={this.setSortBy}
                sortDirection={sortDirection}
                setSortDirection={this.setSortDirection}
                isFetching={isFetching}
                error={error}

                colWidths={colWidths}
            />
        );
    }

    getRequests = () => {
        const { search, currentPage, sortBy, sortDirection } = this.state;

        this.setState({isFetching: true});
        if (search.length > 0) {
            fetchRequestsByValue(search, currentPage, sortBy, sortDirection)
                .then(
                    this.onFetchSuccess,
                    this.onFetchFailure
                )
        } else {
            fetchRequests(currentPage, sortBy, sortDirection)
                .then(
                    this.onFetchSuccess,
                    this.onFetchFailure
                )
        }
    };

    onFetchSuccess = (data) => {
        this.setState({
            pages: data.pages,
            currentPage: data.currentPage,
            requests: data.requests,
            isFetching: false,
        })
    };

    onFetchFailure = () => {
        this.setState({
            isLoading: false,
            error: true,
        });
    };

    setSearch = (search) => {
        this.setState({search}, () => {
            this.getRequests();
        });
    };

    setPage = (currentPage) => {
        this.setState({currentPage}, () => {
            this.getRequests();
        });
    };

    setSortBy = (sortBy) => {
        this.setState({sortBy}, () => {
            this.getRequests();
        });
    };

    setSortDirection = (sortDirection) => {
        this.setState({sortDirection}, () => {
            this.getRequests();
        });
    };
}

export default RequestsTableContainer;
```

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