@ftchinese/ftc-table-react

1.1.3 • Public • Published

ftc-table-react

The React version for ftc-table.

It provides some features for a table: sorting by each column, showing caculating results, fixing the table's head if necessary...

Install

cd yourProject
npm install "@ftchinese/ftc-table-react" --save 

Usage

Example:

import React from 'react';
import ReactDOM from 'react-dom';

import {FtcTable, TableBodyRow} from '@ftchinese/ftc-table-react';


class App extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    const fieldsInfoForTable = [
      {
        "field":"Cheese",
        "fieldName": "Cheese",
        "fieldSubName": "Type of cheese",
        "dataIsNumberic": false,
        "disableSort": false
      },
      {
        "field":"Bread",
        "fieldName": "Bread",
        "fieldSubName": "Type of bread",
        "dataIsNumberic": false,
        "disableSort": false
      },
      {
        "field": "CostGBP",
        "fieldName": "Cost",
        "fieldSubName": "(GBP)",
        "dataIsNumberic": true,
        "disableSort": false
      },
      {
        "field":"CostEUR",
        "fieldName": "Cost",
        "fieldSubName":"(EUR)",
        "dataIsNumberic": true,
        "disableSort": false
      }
    ];
    const captionsInfoForTable = {
      top: "Top Caption",
      bottom: "Bottom Caption"
    };
    const styleListValue = [
      "table--row-stripes"
    ];
    const statisticInfoArr = ['sum', 'mean', 'median'];

    return (
      <FtcTable 
        styleList={styleListValue} 
        fieldsInfo={fieldsInfoForTable} 
        captionsInfo={captionsInfoForTable}  
        addStatisticInfo={statisticInfoArr}
        >
        <TableBodyRow defaultOrder="0" data={
          {
            "Cheese": "cheddar",
            "Bread": "rye",
            "CostGBP":1,
            "CostEUR":1.56
          }
        }/>
        <TableBodyRow defaultOrder="1" data={
          {
            "Cheese": "stilton",
            "Bread": "wholemeal",
            "CostGBP":2,
            "CostEUR":1.85
          }
        }/>
        <TableBodyRow defaultOrder="2" data={
          {
            "Cheese": "red leicester",
            "Bread": "white",
            "CostGBP":3,
            "CostEUR":""
          }
        }/>
      </FtcTable>
    );
  }
}

ReactDOM.render(
  <App />,
  document.getElementById('root')
);

API

The exported components are FtcTable and TableBodyRow .

Props For FtcTable

children

Type Array of or one TableBodyRow. Required. The FtcTable should need TableBodyRow to be as children

fieldsInfo

Type Array of Object. Required. The information data for the fileds of the table's thead.The Object should has following prop:

field

Type String. Required. The unique code for one field.

fieldName

Type String. Optional. The showing name for the field in the thead of table. If it is missing, the field will show instead.

fieldSubName

Type String. Optional. The showing subname for the field in the thead of table.

dataIsNumberic

Type Boolean. Optional. If it is true, the column of data of this field will be regarded as Number, which will effect the result of sorting of the data in the column and the style of the column.

disableSort

Type Boolean. Optional. If it is true, the sorting for the data of this column will be disabled.

captionsInfo

Type Object. Optional. The words for the captions of the table. It has two keys:

top

Type String. Optional. The words for the top caption. If it is missing. The table will have no top caption.

bottom

Type String. Optional. The words for the bottom caption. If it is missing. The table will have no bottom caption.

styleList

Type Array of String or Type String. The style name(s) for the table. There are 5 style names for choosing:

  • ftc-table--row-stripes: Add row stripe related styles to table, making the adjacent 2 rows with 2 colors.
  • ftc-table--horizontal-lines: Add horizontal lines to table.
  • ftc-table--vertical-lines: Add vertical lines to table.
  • "table--responsive-overflow": Add overflow responsive related styles to table.
  • "table--responsive-flat":Add flat responsive related styles to table.

The ftc-table--row-stripesftc-table--horizontal-linesftc-table--vertical-lines can be selected only one or selected two or three at one time.

The table--responsive-overflowtable--responsive-flat should be selected only one at one time. If they are both selected, the one writing last will go into effect. And if there is a prop addWrapperInfo(as follows), both of the responsive style will be invalid.

addStatisticInfo

Type Array. Optional. The item of the Array should be one of 'sum', 'mean', 'median'. If it has values, the corresponding statistical results will be showed in the tfoot. The statistics are only for the column whose data are Number(That's to say, the dataIsNumberic of the column's corresponding data in fieldsInfo is true)

addWrapperInfo

Type Object. Optional. The sizes of the wrapper of the table. It has two keys, width and height, which describe the length of the table's width and height. Both keys are required, if one of the keys are missing or the addWrapperInfo is missing, the table will not have a wrapper. If the table has a wrapper, the thead of the table will be fixed on top when vertically scrolling the content of the table.

The values of width and height can be String or Number. If they are String, they can be values for the CSS properties 'width' and 'height' such as '100%','80px'. If they are Number, they means 'px'.

Props For TableBodyRow

defaultOrder

Type number.Optional. The default index for the row. The initially showing for the rows will follow this order. If it is missing, the initial orders are depended on the writing orders for the TableBodyRow.

data

Type Object. Required. The data for one row. The keys of it should be same as the value of field of the item of fieldsInfo in parent component FtcTable

Readme

Keywords

Package Sidebar

Install

npm i @ftchinese/ftc-table-react

Weekly Downloads

1

Version

1.1.3

License

MIT

Unpacked Size

113 kB

Total Files

7

Last publish

Collaborators

  • neefrankie
  • sunstyle
  • wangyichen