项目作者: saswat3115

项目描述 :
a react data-table component built on react and bootstrap
高级语言: TypeScript
项目地址: git://github.com/saswat3115/react-bs-simple-datatable.git
创建时间: 2018-08-13T08:54:50Z
项目社区:https://github.com/saswat3115/react-bs-simple-datatable

开源协议:MIT License

下载


React-bs-simple-datatable

A react component data-table librabry. Latest version - v1.0.3

data-table

Table of Contents

How to Use

  1. <DataTable
  2. headers={headers}
  3. body={bodyAsJSONArray}
  4. isPaging
  5. pageSize={3}
  6. noOfIndexToBeShown={3}
  7. enableDelete
  8. enableEdit
  9. onRowUpdate={methodToHandleEditingRecord}
  10. enableFilter
  11. ></DataTable>

Datatable Header Configuration

  • Specify header type as IHeaderType[].
  • title is what to show in data table header
  • prop is property name of data source
  • enableSort to enabe sorting to specific column
  • noEdit to restrict editing the specific column
  • type is data type of property
  • optionsOnEdit provides multiple option while on edit mode (provide only when the field is a dropdown)

Following code is a header sample. Pass this headers object to headers props of DataTable component

  1. var headers: IHeaderType[] = [
  2. { title: "Id", prop: "id", enableSort: true, noEdit: true },
  3. { title: "Name", prop: "name", enableSort: true },
  4. { title: "Address", prop: "add" },
  5. { title: "Age", prop: "age", enableSort: true},
  6. { title: "Country", prop: "country", enableSort: true, type: PropDataType.MULTI_OPTION, optionsOnEdit: sampleOptions},
  7. { title: "Status", prop: "status", type: PropDataType.CHECKBOX }
  8. ];
  9. var sampleOptions = [ "USA", "IND", "AUS"];

Header Types

Header type as follows

  1. interface IHeaderType {
  2. title: string;
  3. prop: string;
  4. enableSort?: boolean;
  5. type?: PropDataType;
  6. optionsOnEdit?: any;
  7. noEdit?: boolean;
  8. }

Property types as follows

  1. enum PropDataType {
  2. TEXT, MULTI_OPTION, CHECKBOX
  3. }

Sorting

enableSort: true in header configuration to enable sorting

Paging

  • Provide isPaging to enable pagination
  • Provide pageSize={noOfRecordsPerPage} to show specific number of records per page
  • Provide noOfIndexToBeShown={3} to show number of page indexes in paging div

<DataTable isPaging pageSize={3} noOfIndexToBeShown={3} ></DataTable>

paging snapshot

Filter

Provide eneableFilter props to enable filter operation in datatable
NOTE: By default filter is wild card search from every column

<DataTable enableFilter ></DataTable>

fliter snapshot

Edit

Provide enableEdit props to enable edit button in data table
<DataTable enableEdit ></DataTable>

edit snapshot
edit snapshot on click

Handle Edit Delete Data

Add a event handler to handle modified record.
NOTE: DataTable component temporarily updates the record in memory and emits the modifed record for you.
Pass your method to handle that object as shown below. This will work in both update and delete operation

  1. <DataTable
  2. onRowUpdate={methodToHandleEditingRecord}
  3. ></DataTable>
  4. function methodToHandleEditingRecord(record) {
  5. // record object holds the selected edited record from data source
  6. // update to database
  7. }