2.0.8 • Published 5 years ago

filterable-react-pagination-table v2.0.8

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

react-pagination-table

Build Status

Known Vulnerabilities

Table components for React with pagination

Install

 npm install --save react-pagination-table

Migration

After the version 2.x, the behavior of the className and paginationClassName props will be a little different. For a better way to architect your CSS, the className of the specific components will be more maintainable.

The example or the className section will be helpful to you.

Usage

The module contains two components, includes TableSimpleTablePagination

Demo

There is a data set.

const data = [
    { size: ["L", "M"], phone: 1234567, gender: "Male", age: 20, name:"Ben" },
    { size: ["L", "M", "XL"], phone: 1234567, gender: "Female", age: 22, name:"Ken" },
    { size: ["L", "S"], phone: 1234567, gender: "Female", age: 23, name:"Jay" },
    { size: ["M", "S"], phone: 1234567, gender: "Male", age: 26, name:"Chip" },
    { size: ["XL", "XS"], phone: 1234567, gender: "Male", age: 23, name:"Lee" },
    { size: ["L", "M", "S", "XS"], phone: 1234567, gender: "Female", age: 30, name:"Frank" },
    { size: ["S", "L"], phone: 1234567, gender: "Male", age: 23, name:"CoCo" },
    { size: ["L", "M", "S"], phone: 1234567, gender: "Female", age: 20, name:"Fake" },
    { size: ["XS", "L"], phone: 1234567, gender: "Male", age: 26, name:"Dump" },
    { size: ["L", "M", "S"], phone: 1234567, gender: "Female", age: 27, name:"Ocean" },
    { size: ["S", "XL"], phone: 1234567, gender: "Male", age: 20, name:"Polo" },
    { size: ["M", "XL"], phone: 1234567, gender: "Female", age: 21, name:"Queen" },
    { size: ["L", "M"], phone: 1234567, gender: "Female", age: 20, name:"Bump" },
    { size: ["L", "M", "S", "XL"], phone: 1234567, gender: "Male", age: 22, name:"Judy" },
    { size: ["XL", "M"], phone: 1234567, gender: "Female", age: 24, name:"Ryan" },
    { size: ["L", "S"], phone: 1234567, gender: "Female", age: 25, name:"Flow" },
    { size: ["S", "M"], phone: 1234567, gender: "Female", age: 31, name:"Ray" },
    { size: ["L", "M", "XS"], phone: 1234567, gender: "Male", age: 23, name:"Yen" },
    { size: ["XL", "M", "S"], phone: 1234567, gender: "Male", age: 21, name:"Gray" },
    { size: ["L", "M", "S"], phone: 1234567, gender: "Female", age: 22, name:"Tom" }
];

TableSimple

Simple table component.

import { render } from 'react-dom';
import React from 'react';
import { TableSimple } from 'react-pagination-table';

//Table header
const Header = ["Name", "Age", "Size", "Phone", "Gender" ];

const App = ({Header, data}) =>
    <div>
        <TableSimple
            title="TableSimple"
            subTitle="Sub Title"
            data={ data }
            headers={ Header }
            //Tell the component what order you wanna render.
            columns="name.age.size.phone.gender"
            arrayOption={ [["size", 'all', ', ']] }
        />
    </div>

TablePagination

Simple table with pagination.

import { render } from 'react-dom';
import React from 'react';
import { TablePagination } from 'react-pagination-table';

const Header = ["Name", "Age", "Size", "Phone", "Gender" ];

const App = ({Header, data}) =>
    <div>
        <TablePagination
            title="TablePagination"
            subTitle="Sub Title"
            headers={ Header }
            data={ data }
            columns="name.age.size.phone.gender"
            perPageItemCount={ 5 }
            totalCount={ data.length }
            arrayOption={ [["size", 'all', ' ']] }
        />
    </div>

className

The react-pagination-table(className) and pagination-status(paginationClassName) is the default className and prefix. You can pass custom name by the className and paginationClassName props.

In addition, setting the specific components to the differences styles and status by these class

  • {className} the wrapper of the Component
  • {className}__title
  • {className}__sub-title
  • {className}__header
  • {className}__table(the <table /> tag)
  • {paginationClassName} the wrapper of the Pagination
  • {paginationClassName}__item(the <li /> tags)
  • {paginationClassName}__btn(the page button)
  • {paginationClassName}__btn--active(the activated page button)
  • {paginationClassName}__btn--disable

API

TableSimple

PropsDescriptionTypeDefault
titlethe title at leftStringempty
subTitlethe subTitle at rightStringempty
datathe items you want to renderArrayisRequired
columnsthe order of columnsStringisRequired
headerstable's headerArrayisRequired
arrayOptionproperty: specific which property is array. index: the index of the array, can be a number or allplus: add character between itemsArray[]empty
classNamethe TableSimple classNameStringreact-pagination-table

TablePagination

In addition to the above...

PropsDescriptionTypeDefault
totalCountthe length of the itemsNumberisRequired
perPageItemCountthe numbers of the items on per pageNumberisRequired
nextPageTextthe text of nextPage buttonString下一頁
prePageTextthe text of previousPage buttonString上一頁
paginationClassNamethe pagination classNameStringpagination-status
partialPageCountthe numbers of the page buttonsNumber5

Example

npm start

By default, the example is on the 8000 port after run the command above. Then you can access localhost:8000 to see the demo.

Test

npm test

Other useful component

react-pagination-status

LICENSE

MIT