forked from DevExpress/DevExtreme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
116 lines (115 loc) · 3.32 KB
/
App.js
File metadata and controls
116 lines (115 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import React, { useCallback, useRef, useState } from 'react';
import config from 'devextreme/core/config';
import repaintFloatingActionButton from 'devextreme/ui/speed_dial_action/repaint_floating_action_button';
import DataGrid, {
Column, Editing, Lookup, Texts, Selection,
} from 'devextreme-react/data-grid';
import { SpeedDialAction } from 'devextreme-react/speed-dial-action';
import { SelectBox } from 'devextreme-react/select-box';
import {
employees, states, directions, optionDirections, directionLabel,
} from './data.js';
const App = () => {
const [selectedRowIndex, setSelectedRowIndex] = useState(-1);
const gridRef = useRef(null);
const selectedChanged = useCallback(
(e) => {
setSelectedRowIndex(e.component.getRowIndexByKey(e.selectedRowKeys[0]));
},
[setSelectedRowIndex],
);
const directionChanged = useCallback((e) => {
config({
floatingActionButtonConfig: directions[e.selectedItem],
});
repaintFloatingActionButton();
}, []);
const editRow = useCallback(() => {
gridRef?.current?.instance()?.editRow(selectedRowIndex);
gridRef?.current?.instance()?.deselectAll();
}, [gridRef, selectedRowIndex]);
const deleteRow = useCallback(() => {
gridRef?.current?.instance()?.deleteRow(selectedRowIndex);
gridRef?.current?.instance()?.deselectAll();
}, [gridRef, selectedRowIndex]);
const addRow = useCallback(() => {
gridRef?.current?.instance()?.addRow();
gridRef?.current?.instance()?.deselectAll();
}, [gridRef]);
return (
<div>
<DataGrid
id="grid"
dataSource={employees}
keyExpr="ID"
ref={gridRef}
showBorders={true}
onSelectionChanged={selectedChanged}
>
<Column
dataField="Prefix"
caption="Title"
/>
<Column dataField="FirstName" />
<Column dataField="LastName" />
<Column
dataField="Position"
width={130}
/>
<Column
dataField="StateID"
caption="State"
width={125}
>
<Lookup
dataSource={states}
valueExpr="ID"
displayExpr="Name"
/>
</Column>
<Column
dataField="BirthDate"
dataType="date"
width={125}
/>
<Selection mode="single" />
<Editing mode="popup">
<Texts confirmDeleteMessage="" />
</Editing>
</DataGrid>
<SpeedDialAction
icon="add"
label="Add row"
index={1}
onClick={addRow}
/>
<SpeedDialAction
icon="trash"
label="Delete row"
index={2}
visible={selectedRowIndex !== undefined && selectedRowIndex !== -1}
onClick={deleteRow}
/>
<SpeedDialAction
icon="edit"
label="Edit row"
index={3}
visible={selectedRowIndex !== undefined && selectedRowIndex !== -1}
onClick={editRow}
/>
<div className="options">
<div className="caption">Options</div>
<div className="option">
<span>Direction: </span>
<SelectBox
dataSource={optionDirections}
defaultValue="auto"
inputAttr={directionLabel}
onSelectionChanged={directionChanged}
/>
</div>
</div>
</div>
);
};
export default App;