File tree 3 files changed +74
-39
lines changed
3 files changed +74
-39
lines changed Original file line number Diff line number Diff line change @@ -9,14 +9,14 @@ export default class Cell extends React.Component {
9
9
render ( ) {
10
10
const { value, onEdit, data} = this . props
11
11
12
- if ( Array . isArray ( value ) ) {
12
+ if ( value instanceof Object ) {
13
13
return < td >
14
14
< select className = "form-control"
15
15
data-column = { data . columnIndex }
16
16
data-row = { data . rowIndex }
17
17
onChange = { onEdit }
18
- value = { value } >
19
- { value . map ( ( item , i ) => < option key = { i } > { item } </ option > ) }
18
+ value = { value . selected } >
19
+ { value . items . map ( ( item , i ) => < option key = { i } > { item } </ option > ) }
20
20
</ select >
21
21
</ td >
22
22
}
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+
3
+ export default class CellDropdown extends React . Component {
4
+ state = { }
5
+
6
+ componentDidMount ( ) {
7
+ this . setState ( { value : this . props . value } )
8
+ }
9
+ onChange ( e , data ) {
10
+ this . props . onChange ( e , this . state . value , data )
11
+ }
12
+
13
+ render ( ) {
14
+ const { value, data} = this . props
15
+ return < select className = "form-control"
16
+ onChange = { this . onChange . bind ( this , { data, value : this . state . value } ) }
17
+ value = { value . selected } >
18
+ { value . items . map ( ( item , i ) => < option key = { i } > { item } </ option > ) }
19
+ </ select >
20
+ }
21
+ }
Original file line number Diff line number Diff line change @@ -3,41 +3,60 @@ import React, {Component} from 'react'
3
3
import Layout from "../components/Layout" ;
4
4
import DinamicTable from "../components/DinamicTable" ;
5
5
6
+ const table = {
7
+ dataSource : [
8
+ [
9
+ "asdasd" ,
10
+ 23 ,
11
+ 343 ,
12
+ {
13
+ selected : 'hello' ,
14
+ items : [ "hello" , 'rich' , 23 ]
15
+ }
6
16
7
- export default class Index extends Component {
17
+ ] ,
18
+ [
19
+ "asdasd" ,
20
+ 23 ,
21
+ 343 ,
22
+ ] ,
23
+ [
24
+ "asdasd" ,
25
+ 23 ,
26
+ 343 ,
27
+ ] ,
28
+ [
29
+ "asdasd" ,
30
+ 23 ,
31
+ 343 ,
32
+ ] ,
33
+ ] ,
34
+ columns : [
35
+ 'TEXT' ,
36
+ 'NUMBER 1' ,
37
+ 'NUMBER 2' ,
38
+ 'SUM' ,
39
+ 'DROPDOWN' ,
40
+ ]
41
+ }
8
42
43
+ export default class Index extends Component {
9
44
10
45
state = {
11
- dataSource : [
12
- [
13
- "asdasd" ,
14
- 23 ,
15
- 343 ,
16
- [ "hello" , 'rich' , 23 ]
17
- ] ,
18
- [
19
- "asdasd" ,
20
- 23 ,
21
- 343 ,
22
- ] ,
23
- [
24
- "asdasd" ,
25
- 23 ,
26
- 343 ,
27
- ] ,
28
- [
29
- "asdasd" ,
30
- 23 ,
31
- 343 ,
32
- ] ,
33
- ] ,
34
- columns : [
35
- 'TEXT' ,
36
- 'NUMBER 1' ,
37
- 'NUMBER 2' ,
38
- 'SUM' ,
39
- 'DROPDOWN' ,
40
- ]
46
+ columns : [ ] ,
47
+ dataSource : [ ]
48
+ }
49
+
50
+ componentDidMount ( ) {
51
+ const dataSource = table . dataSource
52
+ const columns = table . columns
53
+
54
+ dataSource . forEach ( ( item , index ) => {
55
+ while ( item . length < columns . length ) {
56
+ item . push ( "" )
57
+ }
58
+ } )
59
+ this . setState ( { dataSource, columns} )
41
60
}
42
61
43
62
editCell ( { target} ) {
@@ -68,7 +87,6 @@ export default class Index extends Component {
68
87
handleAddColumn ( ) {
69
88
const { columns, dataSource} = this . state
70
89
71
-
72
90
columns . push ( 'column name' )
73
91
74
92
dataSource . forEach ( ( item , index ) => {
@@ -81,11 +99,7 @@ export default class Index extends Component {
81
99
82
100
handleAddRow ( ) {
83
101
const { columns, dataSource} = this . state
84
-
85
-
86
102
dataSource . push ( Array ( columns . length ) . fill ( "" ) )
87
-
88
-
89
103
this . setState ( { dataSource} )
90
104
}
91
105
You can’t perform that action at this time.
0 commit comments