Wijmo 5 - Multi-Column Combo as Grid Editor
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/interop/angular/wijmo.angular.min.js"></script>
<!-- mark this as an Angular application and give it a controller -->
<div ng-app="app" ng-controller="appCtrl" class="container">
<h1>Multi-Column Combo as Grid Editor</h1>
<p>This is a <b>FlexGrid</b> control:</p>
<wj-flex-grid items-source="data">
<wj-flex-grid-column header="Country" binding="country"></wj-flex-grid-column>
<wj-flex-grid-column
header="TheCombo"
is-read-only="true"
css-class="no-padding"
binding="country">
<wj-cell-template>
<wj-combo-box
items-source="comboData"
header-path="country"
display-member-path="country"
selected-value-path="country"
selected-value="$item.country"
initialized="initCombo(s,e)">
</wj-combo-box>
</wj-cell-template>
</wj-flex-grid-column>
<wj-flex-grid-column header="Sales" binding="sales"></wj-flex-grid-column>
<wj-flex-grid-column header="Expenses" binding="expenses"></wj-flex-grid-column>
<wj-flex-grid-column header="Downloads" binding="downloads"></wj-flex-grid-column>
</wj-flex-grid>
</div>
CSS
.wj-flexgrid {
height: 150px;
margin-top:10px;
}
.wj-cell {
padding: 3px;
}
.no-padding {
padding: 0;
}
.no-padding .wj-control {
border: none;
border-radius: 0;
}
td {
padding-right: 6px;
}
JavaScript
// define app, include Wijmo 5 directives
var app = angular.module('app', ['wj']);
// controller
app.controller('appCtrl', function($scope) {
// create some random data
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
data = [];
for (var i = 0; i < countries.length; i++) {
data.push({
id: i,
country: countries[i],
downloads: Math.round(Math.random() * 20000),
sales: Math.random() * 10000,
expenses: Math.random() * 5000
});
}
$scope.data = new wijmo.collections.CollectionView(data);
$scope.comboData = JSON.parse(JSON.stringify(data));
$scope.initCombo = function(s, e) {
// format items as single-row tables
s.listBox.formatItem.addHandler(function(s, e) {
e.item.innerHTML = '<table><tr>' +
'<td style="width:30px;text-align:right">' + e.data.id + '</td>' +
'<td style="width:100px">' + e.data.country + '</td>' +
'<td style="width:80px;text-align:right">' +
wijmo.Globalize.format(e.data.downloads, 'n0') +
'</td>' +
'<td style="width:80px;text-align:right">' +
wijmo.Globalize.format(e.data.sales, 'n0') +
'</td>' +
'</tr></table>';
})
s.refresh();
// refresh grid to show changes
s.textChanged.addHandler(function(s, e) {
$scope.data.refresh();
});
}
});