Skip to content

Commit d6d979b

Browse files
Initial code commit
1 parent 5a5c691 commit d6d979b

File tree

7 files changed

+698
-1
lines changed

7 files changed

+698
-1
lines changed

README.md

Lines changed: 197 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,198 @@
1-
# react-datatable
1+
# React Datatable
2+
23
ReactDatatable is a component which provide ability to create multifunctional table using single component like jQuery Datatable. It's fully customizable and easy to integrate in any react component. Bootstrap compatible.
4+
5+
## Features
6+
* Lightweight
7+
* Fully customizable (JSX, templates, state, styles, callbacks)
8+
* Client-side & pagination
9+
* Multi-sort
10+
* Filters
11+
* Minimal design
12+
* Fully controllable via optional props and callbacks
13+
14+
## Usage
15+
16+
```js
17+
import React, { Component, Fragment } from 'react';
18+
import { render} from 'react-dom';
19+
import ReactDatatable from '@ashvin27/react-datatable';
20+
21+
class App extends Component {
22+
constructor(props) {
23+
super(props);
24+
this.columns = [
25+
{
26+
key: "name",
27+
text: "Name",
28+
className: "name",
29+
align: "left",
30+
sortable: true,
31+
},
32+
{
33+
key: "address",
34+
text: "Address",
35+
className: "address",
36+
align: "left",
37+
sortable: true
38+
},
39+
{
40+
key: "postcode",
41+
text: "Postcode",
42+
className: "postcode",
43+
sortable: true
44+
},
45+
{
46+
key: "rating",
47+
text: "Rating",
48+
className: "rating",
49+
align: "left",
50+
sortable: true
51+
},
52+
{
53+
key: "type_of_food",
54+
text: "Type of Food",
55+
className: "type_of_food",
56+
sortable: true,
57+
align: "left"
58+
},
59+
{
60+
key: "action",
61+
text: "Action",
62+
className: "action",
63+
width: 100,
64+
align: "left",
65+
sortable: false,
66+
cell: record => {
67+
return (
68+
<Fragment>
69+
<button
70+
className="btn btn-primary btn-sm"
71+
onClick={() => this.editRecord(record)}
72+
style={{marginRight: '5px'}}>
73+
<i className="fa fa-edit"></i>
74+
</button>
75+
<button
76+
className="btn btn-danger btn-sm"
77+
onClick={() => this.deleteRecord(record)}>
78+
<i className="fa fa-trash"></i>
79+
</button>
80+
</Fragment>
81+
);
82+
}
83+
}
84+
];
85+
this.config = {
86+
page_size: 10,
87+
length_menu: [ 10, 20, 50 ],
88+
button: {
89+
excel: true,
90+
print: true
91+
}
92+
}
93+
94+
this.state = {
95+
records: [
96+
{
97+
"id": "55f14312c7447c3da7051b26",
98+
"address": "228 City Road",
99+
"name": ".CN Chinese",
100+
"postcode": "3JH",
101+
"rating": 5,
102+
"type_of_food": "Chinese"
103+
},
104+
{
105+
"id": "55f14312c7447c3da7051b27",
106+
"address": "376 Rayleigh Road",
107+
"name": "@ Thai",
108+
"postcode": "5PT",
109+
"rating": 5.5,
110+
"type_of_food": "Thai"
111+
},
112+
{
113+
"id": "55f14312c7447c3da7051b28",
114+
"address": "30 Greyhound Road Hammersmith",
115+
"name": "@ Thai Restaurant",
116+
"postcode": "8NX",
117+
"rating": 4.5,
118+
"type_of_food": "Thai"
119+
},
120+
{
121+
"id": "55f14312c7447c3da7051b29",
122+
"address": "30 Greyhound Road Hammersmith",
123+
"name": "@ Thai Restaurant",
124+
"postcode": "8NX",
125+
"rating": 4.5,
126+
"type_of_food": "Thai"
127+
}
128+
]
129+
}
130+
}
131+
132+
editRecord(record) {
133+
console.log("Edit Record", record);
134+
}
135+
136+
deleteRecord(record) {
137+
console.log("Delete Record", record);
138+
}
139+
140+
render() {
141+
return (
142+
<div>
143+
<ReactDatatable
144+
config={this.config}
145+
records={this.state.records}
146+
columns={this.columns}
147+
/>
148+
</div>
149+
)
150+
}
151+
}
152+
153+
render(<App />, document.getElementById("app"));
154+
```
155+
156+
# API
157+
158+
```js
159+
import ReactDatatable from '@ashvin27/react-datatable';
160+
or
161+
var ReactDatatable = require('@ashvin27/react-datatable')
162+
```
163+
## Props
164+
| Name | Type | Description
165+
| ------------- | ------------- | ------------- |
166+
| config | Object[] | This props will used to specify datatable configuration
167+
| records | Object[] | This props will used to pass records/data to datatable
168+
| columns | Object[] | This props will used to specify datatable column configuration
169+
170+
## Options
171+
| Name | Type | default | Description
172+
| ------------- | ------------- | ------------- | ------------- |
173+
| className | String | | Datatable additional class, use to appy additional styling on table
174+
| id | String | | Identifier of datatable
175+
| page_size | Number | 10 | Specify the page length (number of rows per page)
176+
| length_menu | Array[] | [10, 25, 50, 75, 100] | Specify the options in the page length `select` list.
177+
| filename | String | "table" | Specify the export filename
178+
| button | Object[] | { excel: false, print: false } | Use to enable/disable export buttons. By default buttons are disabled.
179+
| sort | Object[] | { column: "", order: "asc" } | Initial sorting order to apply to the datatable
180+
181+
## Columns
182+
| Name | Type | default | Description
183+
| ------------- | ------------- | ------------- | ------------- |
184+
| key | String | | Specify the key of record which value will display in table cell
185+
| text | String | | Spcify the table column text
186+
| className | String | | Table column additional class fo styling
187+
| align | String | left | Specify the content alignment
188+
| width | Number | | Specify the column width
189+
| sortable | Boolean | false | Specify the column is sortable of not
190+
| cell | Function(record):string | | Datatable
191+
192+
## Install
193+
194+
With [npm](https://npmjs.org/) installed, run
195+
196+
```
197+
npm i @ashvin27/react-datatable
198+
```

package.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "@ashvin27/react-datatable",
3+
"version": "1.1.2",
4+
"description": "ReactDatatable is a component which provide ability to create multifunctional table using single component like jQuery Datatable",
5+
"main": "./lib/index.js",
6+
"author": "Ashvin Patel",
7+
"license": "MIT",
8+
"scripts": {
9+
"test": "echo \"Error: no test specified\" && exit 1",
10+
"start": "webpack --watch",
11+
"build": "webpack"
12+
},
13+
"peerDependencies": {
14+
"react": "^16.0.0",
15+
"react-dom": "^16.0.0",
16+
"js2excel": "^1.0.1",
17+
"lodash": "^4.17.11"
18+
},
19+
"devDependencies": {
20+
"babel-cli": "^6.26.0",
21+
"babel-core": "^6.26.3",
22+
"babel-loader": "^7.1.4",
23+
"babel-plugin-transform-object-rest-spread": "^6.26.0",
24+
"babel-plugin-transform-react-jsx": "^6.24.1",
25+
"babel-preset-env": "^1.7.0",
26+
"babel-runtime": "^6.26.0",
27+
"css-loader": "^2.0.0",
28+
"file-loader": "^2.0.0",
29+
"react": "^16.4.0",
30+
"react-dom": "^16.4.0",
31+
"style-loader": "^0.23.1",
32+
"url-loader": "^1.1.2",
33+
"react-scripts": "1.1.4",
34+
"webpack": "^3.10.0"
35+
},
36+
"dependencies": {
37+
"js2excel": "^1.0.1",
38+
"lodash": "^4.17.11"
39+
},
40+
"keywords": [
41+
"react",
42+
"reactjs",
43+
"react-datatable",
44+
"react-data-table",
45+
"datatable",
46+
"datagrid",
47+
"jquery datatable",
48+
"react-component"
49+
]
50+
}

0 commit comments

Comments
 (0)