Skip to content

Commit f531c56

Browse files
committed
v1.0.20
1 parent 35dbee3 commit f531c56

File tree

4 files changed

+141
-9
lines changed

4 files changed

+141
-9
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const getFancyGrid = () => {
3535
return (
3636
<div style={{marginTop: '5px'}}>
3737
<Form
38+
id={'myForm'}
3839
theme={'extra-gray'}
3940
title={'Form'}
4041
items={[{
@@ -44,15 +45,31 @@ const getFancyGrid = () => {
4445
label: 'Name',
4546
emptyText: 'Name',
4647
name: 'name'
47-
}, {
48+
},{
4849
label: 'SurName',
4950
emptyText: 'SurName',
5051
name: 'surname'
52+
}]}
53+
buttons={[{
54+
text: 'Save',
55+
handler: () => {
56+
let grid = Fancy.getGrid('myGrid'),
57+
form = Fancy.getForm('myForm'),
58+
values = form.get(),
59+
id = values.id;
60+
61+
grid.setById(id, values);
62+
grid.update({
63+
type: 'row'
64+
});
65+
}
5166
}]}>
5267
</Form>
5368
<Grid
69+
id={'myGrid'}
5470
height={500}
5571
theme={'extra-gray'}
72+
exporter={true}
5673
selModel={{
5774
activeCell: true,
5875
type: 'rows'
@@ -61,6 +78,13 @@ const getFancyGrid = () => {
6178
resizable: true,
6279
menu: true
6380
}}
81+
events={[{
82+
selectrow: (grid, rowIndex, dataItem: any) => {
83+
let form = Fancy.getForm('myForm');
84+
85+
form.set(dataItem.data);
86+
}
87+
}]}
6488
columns={getColumns()}
6589
data={getData()}>
6690
</Grid>

dist/fancygrid-react.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,47 @@
11
import React from 'react';
22
import Fancy from 'fancygrid';
33

4+
const CHANGABLE_GRID_PROPS = {
5+
title: {
6+
type: 'string',
7+
handler: (grid, value)=>{
8+
console.log(value);
9+
grid.setTitle(value);
10+
}
11+
},
12+
subTitle: {
13+
type: 'string',
14+
handler: (grid, value)=>{
15+
grid.setSubTitle(value);
16+
}
17+
},
18+
columns: {
19+
type: 'array',
20+
handler: (grid, columns)=>{
21+
grid.setColumns(columns);
22+
}
23+
},
24+
data: {
25+
type: 'array',
26+
handler: (grid, data)=>{
27+
grid.setData(data);
28+
grid.update();
29+
}
30+
},
31+
width: {
32+
type: 'number',
33+
handler: (grid, value)=>{
34+
grid.setWidth(value);
35+
}
36+
},
37+
height: {
38+
type: 'number',
39+
handler: (grid, value)=>{
40+
grid.setHeight(value);
41+
}
42+
}
43+
};
44+
445
class Grid extends React.Component {
546
render() {
647
let me = this,
@@ -40,6 +81,66 @@ class Grid extends React.Component {
4081
this.widget.destroy(false);
4182
}
4283
}
84+
85+
componentDidUpdate(prevProps) {
86+
this.processPropsChanges(prevProps, this.props);
87+
}
88+
89+
shouldComponentUpdate(nextProps) {
90+
this.processPropsChanges(this.props, nextProps);
91+
return false;
92+
}
93+
94+
processPropsChanges(prevProps, nextProps) {
95+
let changes = this.getChanges(prevProps, nextProps);
96+
}
97+
98+
getChanges(prevProps, nextProps) {
99+
for(let p in prevProps){
100+
if(!CHANGABLE_GRID_PROPS[p]){
101+
continue;
102+
}
103+
104+
let prevValue = prevProps[p],
105+
nextValue = nextProps[p],
106+
type = CHANGABLE_GRID_PROPS[p].type;
107+
108+
if(Fancy.typeOf(prevValue) !== type || Fancy.typeOf(nextValue) !== type){
109+
continue;
110+
}
111+
112+
switch(type){
113+
case 'string':
114+
case 'number':
115+
if(prevValue !== nextValue){
116+
CHANGABLE_GRID_PROPS[p].handler(this.widget, nextValue);
117+
}
118+
break;
119+
case 'array':
120+
if(prevValue.length !== nextValue.length){
121+
CHANGABLE_GRID_PROPS[p].handler(this.widget, nextValue);
122+
}
123+
else{
124+
prevValue.some((item, i) => {
125+
if(typeof item === 'object'){
126+
for(let q in item){
127+
if(item[q] !== nextValue[i][q]){
128+
CHANGABLE_GRID_PROPS[p].handler(this.widget, nextValue);
129+
return true;
130+
}
131+
}
132+
}
133+
});
134+
}
135+
break;
136+
case 'object':
137+
if(prevValue.toString() !== nextValue.toString()){
138+
CHANGABLE_GRID_PROPS[p].handler(this.widget, nextValue);
139+
}
140+
break;
141+
}
142+
}
143+
}
43144
}
44145

45146
class Form extends React.Component {

dist/fancygrid-react.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"name": "fancygrid-react",
3-
"version": "1.0.19",
3+
"version": "1.0.20",
44
"description": "React components to generate interactive javascript grids using the FancyGrid library",
5-
"main": "dist/fancygrid-react.min.js",
5+
"main": "dist/fancygrid-react.js",
66
"author": "FancyGrid",
77
"homepage": "https://fancygrid.com",
8-
"scripts": {},
8+
"scripts": {
9+
"build": "gulp && gulp prod"
10+
},
911
"keywords": [
1012
"react",
1113
"react-component",
@@ -15,11 +17,16 @@
1517
"javascript",
1618
"fancygrid"
1719
],
18-
"license": "MIT",
20+
"license": "Commercial",
1921
"devDependencies": {
20-
"@babel/core": "^7.12.3",
21-
"@babel/preset-env": "^7.12.1",
22-
"fancygrid": "^1.7.129",
22+
"@babel/core": "^7.12.7",
23+
"@babel/preset-env": "^7.12.7",
24+
"fancygrid": "^1.7.139",
25+
"gulp": "^4.0.2",
26+
"gulp-babel": "^8.0.0",
27+
"gulp-concat": "^2.6.1",
28+
"gulp-react": "^4.0.0",
29+
"gulp-uglify": "^3.0.2",
2330
"react": "^16.2.0"
2431
},
2532
"peerDependencies": {

0 commit comments

Comments
 (0)