1 | # Using Custom Editors
|
2 |
|
3 | Editors are defined on the `columns` object, and specify how cells that fall under their parent column will be edited when the row is in editmode. By default, cells in editmode will be displayed as `<text />` inputs.
|
4 |
|
5 | ##### By default, cells have the following HTML:
|
6 |
|
7 | ````html
|
8 | <td>
|
9 | <span>
|
10 | { value }
|
11 | </span>
|
12 | </td>
|
13 | ````
|
14 |
|
15 | ##### The very same cell, when in editmode, will be displayed as:
|
16 |
|
17 | ````html
|
18 | <td>
|
19 | <span>
|
20 | <input type="text" value={ value } />
|
21 | </span>
|
22 | </td>
|
23 | ````
|
24 |
|
25 | This behavior can be overridden by defining an editor on the `columns` object:
|
26 |
|
27 |
|
28 | ##### Example Dropdown Editor
|
29 |
|
30 | **Definition**:
|
31 |
|
32 | ````js
|
33 |
|
34 | import StateEditor from './editors/State';
|
35 |
|
36 | const columns = [
|
37 | {
|
38 | name: 'State',
|
39 | dataIndex: 'state',
|
40 | editor: StateEditor
|
41 | }, //...
|
42 | ];
|
43 | ````
|
44 |
|
45 | **Implementation**:
|
46 |
|
47 | ````js
|
48 |
|
49 | import { Actions } from 'react-redux-grid';
|
50 |
|
51 | import statesOptions from './../constants/stateDefinitions';
|
52 |
|
53 | export default const stateEditor = ({
|
54 | column, columns, value, stateKey, store, rowId
|
55 | }) => {
|
56 |
|
57 | const dropdownProps = {
|
58 | value: value,
|
59 | onChange: handleChange.bind(
|
60 | null, { store, stateKey, column, columns, rowId }
|
61 | )
|
62 | };
|
63 |
|
64 | return (
|
65 | <select { ...dropdownProps }>
|
66 | { stateOptions }
|
67 | </select>
|
68 | );
|
69 |
|
70 | };
|
71 |
|
72 | export const handleChange = ({
|
73 | store, stateKey, column, columns, rowId
|
74 | }, event) => {
|
75 |
|
76 | const target = event.target;
|
77 |
|
78 | return store.dispatch(
|
79 | Actions.EditorActions.updateCellValue({
|
80 | column,
|
81 | columns,
|
82 | name: column.dataIndex,
|
83 | rowId,
|
84 | stateKey,
|
85 | value: target[target.options[target.selectedIndex]
|
86 | })
|
87 | );
|
88 |
|
89 | };
|
90 |
|
91 | ````
|
92 |
|
93 | When in editmode, this column will be rendered with the following HTML:
|
94 |
|
95 |
|
96 | ````html
|
97 | <td>
|
98 | <span>
|
99 | <select value= { value }>
|
100 | <option>Texas</option>
|
101 | <!-- more states ... -->
|
102 | </select>
|
103 | </span>
|
104 | </td>
|
105 | ````
|
106 |
|
\ | No newline at end of file |