-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathexample-drag-row-between-grids.html
More file actions
243 lines (216 loc) · 6.63 KB
/
Copy pathexample-drag-row-between-grids.html
File metadata and controls
243 lines (216 loc) · 6.63 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="shortcut icon" type="image/ico" href="favicon.ico" />
<title>SlickGrid example: Dragging a row between grids</title>
<link rel="stylesheet" href="../dist/styles/css/example-demo.css" type="text/css"/>
<link rel="stylesheet" href="../dist/styles/css/slick-icons.css" type="text/css"/>
<link rel="stylesheet" href="../dist/styles/css/slick-alpine-theme.css" type="text/css"/>
<style>
.cell-effort-driven {
justify-content: center;
}
.cell-drag-cross-grid {
cursor: move;
/* background-color: rgb(235, 235, 235); */
}
.cell-selection {
border-right-color: silver;
border-right-style: solid;
background: #f5f5f5;
color: gray;
text-align: right;
font-size: 10px;
}
.slick-row.selected .cell-selection {
background-color: transparent; /* show default selected row background */
}
.recycle-bin {
width: 120px;
border: 1px solid gray;
background: beige;
padding: 4px;
font-size: 12pt;
font-weight: bold;
color: black;
text-align: center;
-moz-border-radius: 10px;
}
.red {
background: red;
}
.bold {
font-weight: bold;
}
</style>
</head>
<body>
<h2 class="title">Example - Drag Row between Grids</h2>
<div style="position:relative">
<div style="width:600px;">
<div class="grid-header" style="width:100%">
<label>Santa's TODO list:</label>
</div>
<div id="myGrid" style="width:100%;height:200px;"></div>
</div>
<br/>
<div style="width:600px;">
<div class="grid-header" style="width:100%">
<label>Shopping list:</label>
</div>
<div id="myGrid2" class="example-grid slick-container" style="width:100%;height:200px;"></div>
</div>
<div class="options-panel">
<h2>
<a href="/examples/index.html" style="text-decoration: none; font-size: 22px">⌂</a>
Tips:
</h2>
<hr/>
<div style="padding:6px;">
<b>Drag rows from the top grid to the bottom grid</b><br/>
Click to select, Ctrl-click to toggle selection, Shift-click to select a range.<br/>
Drag one or more rows by the handle (the grey box on the left) from the top grid to the bottom grid.<br/>
To drag in both directions, you would need to set up a second plugin going the other way.
<h2>View Source:</h2>
<ul>
<li><A href="https://github.com/6pac/SlickGrid/blob/master/examples/example-drag-row-between-grids.html" target="_sourcewindow"> View the source for this example on Github</a></li>
</ul>
</div>
</div>
</div>
<script src="../dist/browser/slick.core.js"></script>
<script src="../dist/browser/slick.interactions.js"></script>
<script src="../dist/browser/slick.grid.js"></script>
<script src="../dist/browser/plugins/slick.cellrangedecorator.js"></script>
<script src="../dist/browser/plugins/slick.cellrangeselector.js"></script>
<script src="../dist/browser/plugins/slick.cellselectionmodel.js"></script>
<script src="../dist/browser/plugins/slick.rowselectionmodel.js"></script>
<script src="../dist/browser/plugins/slick.crossgridrowmovemanager.js"></script>
<script src="../dist/browser/slick.formatters.js"></script>
<script src="../dist/browser/slick.editors.js"></script>
<script>
var grid, grid2;
var data = [], data2 = [];
var columns = [
{
id: "#",
name: "",
width: 15,
behavior: "selectAndMove",
selectable: false,
resizable: false,
cssClass: "cell-drag-cross-grid dnd",
formatter: () => `<span class="sgi sgi-drag"></span>`
},
{
id: "name",
name: "Name",
field: "name",
width: 300,
cssClass: "cell-title",
editor: Slick.Editors.Text,
validator: requiredFieldValidator
},
{
id: "complete",
name: "Complete",
width: 60,
cssClass: "cell-effort-driven",
field: "complete",
cannotTriggerInsert: true,
formatter: Slick.Formatters.Checkmark,
editor: Slick.Editors.Checkbox
}
];
var columns2 = [
{
id: "name",
name: "Name",
field: "name",
width: 300,
cssClass: "cell-title",
editor: Slick.Editors.Text,
validator: requiredFieldValidator
},
{
id: "complete",
name: "Complete",
width: 60,
cssClass: "cell-effort-driven",
field: "complete",
cannotTriggerInsert: true,
formatter: Slick.Formatters.Checkmark,
editor: Slick.Editors.Checkbox
}
];
var options = {
editable: true,
enableAddRow: true,
enableCellNavigation: true,
forceFitColumns: true,
autoEdit: false
};
function requiredFieldValidator(value) {
if (value == null || value == undefined || !value.length) {
return {valid: false, msg: "This is a required field"};
} else {
return {valid: true, msg: null};
}
}
document.addEventListener("DOMContentLoaded", function() {
data = [
{ name: "Make a list", complete: true},
{ name: "Check it twice", complete: false},
{ name: "Find out who's naughty", complete: false},
{ name: "Find out who's nice", complete: false}
];
data2 = [
{ name: "Onions", complete: true},
{ name: "Vegemite", complete: false},
{ name: "Corn Flakes", complete: false},
{ name: "Beans", complete: false}
];
grid = new Slick.Grid("#myGrid", data, columns, options);
grid.setSelectionModel(new Slick.RowSelectionModel({
dragToSelect: true
}));
toGrid = new Slick.Grid("#myGrid2", data2, columns2, options);
toGrid.setSelectionModel(new Slick.RowSelectionModel({
dragToSelect: true
}));
var moveRowsPlugin = new Slick.CrossGridRowMoveManager({
cancelEditOnDrag: true,
toGrid: toGrid
});
moveRowsPlugin.onMoveRows.subscribe(function (e, args) {
var extractedRows = [], selectedRowIndexes = [], left, right;
var rows = args.rows;
// insert moved rows into data array
left = data2.slice(0, args.insertBefore);
right = data2.slice(args.insertBefore, data2.length);
for (var i = 0; i < rows.length; i++) {
extractedRows.push(data[rows[i]]);
}
data2 = left.concat(extractedRows.concat(right));
// set up row selections in new grid
for (var i = 0; i < rows.length; i++)
selectedRowIndexes.push(left.length + i);
toGrid.resetActiveCell();
toGrid.setData(data2);
toGrid.setSelectedRows(selectedRowIndexes);
toGrid.render();
});
grid.registerPlugin(moveRowsPlugin);
grid.onAddNewRow.subscribe(function (e, args) {
var item = {name: "New task", complete: false};
Slick.Utils.extend(item, args.item);
data.push(item);
grid.invalidateRows([data.length - 1]);
grid.updateRowCount();
grid.render();
});
});
</script>
</body>
</html>