KB - Wijmo 5 - Move Data Between Grida
Shows how to move data between two different FlexGrids
by Joel Parks
HTML
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://cdn.wijmo.com/5.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.chart.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.filter.min.js"></script>
<div class="container">
<h1>
FlexGrid - Move Data Between Grids
</h1>
<label>FlexGrid One</label>  <button id="gridOneButton">Move Selected Row</button>
<div id="flexGrid" class="custom-icons" style="font-family:Courier New"></div>
<label>FlexGrid Two</label>  <button id="gridTwoButton">Move Selected Row</button>
<div id="flexGrid1" class="custom-icons" style="font-family:Courier New"></div>
</div>
CSS
.wj-flexgrid {
max-height: 250px;
margin-bottom: 12px;
}
.header {
display: inline-block;
width: 150px;
text-align: right;
font-weight: normal;
}
// Changes the icon for filtering the grid
.custom-icons .wj-glyph-filter {
background-image:url('http://icons.iconseeker.com/png/fullsize/aspnet/filter-1.png');
background-repeat: no-repeat;
background-position: bottom right;
margin-top: 4px;
width: 1em; height: 1em;
border: none;
}
.custom-icons .wj-glyph-filter:after {
display: none;
}
/* make active filter images 25% larger */
.custom-icons .wj-filter-on .wj-glyph-filter {
transform: scale(1.25)
}
JavaScript
onload = function() {
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
data = [], data1 = [];
for (var i = 0; i < countries.length; i++) {
data.push({
id: i,
country: countries[i],
active: i % 5 != 0,
downloads: Math.round(Math.random() * 200000),
sales: Math.random() * 100000,
expenses: Math.random() * 50000
});
}
for (var j = 0; j < countries.length; j++) {
data1.push({
id: j + 6,
country: countries[j],
active: j % 5 != 0,
downloads: Math.round(Math.random() * 200000),
sales: Math.random() * 100000,
expenses: Math.random() * 50000
});
}
var gridView = new wijmo.collections.CollectionView(data);
var gridView1 = new wijmo.collections.CollectionView(data1);
var gridArray = new wijmo.grid.FlexGrid('#flexGrid', {
autoGenerateColumns: false,
columns: [{
binding: "id",
header: "ID"
}, {
binding: "country",
header: "COUNTRY",
width: "*"
}, {
binding: "downloads",
header: "DOWNLOADS"
}, {
binding: "sales",
header: "SALES"
}, {
binding: "expenses",
header: "EXPENSES"
}],
itemsSource: gridView,
allowDragging: 2,
selectionMode: 3
});
var gridArray1 = new wijmo.grid.FlexGrid('#flexGrid1', {
autoGenerateColumns: false,
columns: [{
binding: "id",
header: "ID"
}, {
binding: "country",
header: "COUNTRY",
width: "*"
}, {
binding: "downloads",
header: "DOWNLOADS"
}, {
binding: "sales",
header: "SALES"
}, {
binding: "expenses",
header: "EXPENSES"
}],
itemsSource: gridView1,
allowDragging: 2,
selectionMode: 3
});
function gridOneMove() {
console.log(gridArray.getCellData(1, 2, true));
console.log(gridArray.getCellData(1, 2, false));
data1.push(gridArray.rows[gridArray.selection.row].dataItem);
gridArray.rows.splice(gridArray.selection.row,...