Wijmo 5 [Grid last row set for editing and scroll]
Prevent Delete/BackSpace in DeataMap
by Manish Gupta
HTML
<link rel="stylesheet" href="http://cdn.wijmo.com/5.20171.282/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.20171.282/controls/wijmo.min.js"></script>
<script src="http://cdn.wijmo.com/5.20171.282/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.20171.282/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.20171.282/interop/angular/wijmo.angular.min.js"></script>
<div ng-app="app" ng-controller="appCtrl">
<p>Wijmo <b>FlexGrid</b>
</p>
<p>
<br/>Enter any value less than 1000 in sales column and observe that it does not allow you to exit the edit mode</p>
<wj-flex-grid items-source="data" initialized="init(s,e)" style="height:200px">
<wj-flex-grid-column header="Country" binding="country"></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
.isError {
background-color: 'red';
color: white;
}
JavaScript
// define app, include Wijmo 5 directives
var app = angular.module('app', ['wj']);
// controller
app.controller('appCtrl', function ($scope) {
$scope.init = function (sender, args) {
sender.columns[0].dataMap=new wijmo.grid.DataMap(dataMap,'country','country');
sender.columns[0].showDropDown=true;
sender.prepareCellForEdit.addHandler(function(s, e) {
var row = s.rows[e.row];
var column = s.columns[e.col];
console.log(column)
if (column.showDropDown) {//Dropdowns should not have editor
var cell = sender.cells.getCellElement(e.row, e.col);
if (cell !== null) {
var gridEditor = cell.getElementsByClassName("wj-grid-editor");console.log(gridEditor)
if (gridEditor.length > 0) {
gridEditor[0].addEventListener("keydown",function(evt){
console.log(evt);
if(evt.which==46||evt.which==8){
evt.preventDefault();
}
},true)
}
}
e.cancel = true;
return;
}
});
}
// create some random data
var countries = 'US,Germany,UK,Japan,Italy,Greece,a,b,c,d,e,f,g,h,i,j,k,l,m,v,c,d,e,r,t,y,u,d'.split(','),
data = [];
var dataMap=[];
for(var i=0;i<countries.length;i++){
dataMap.push({
id:i,
country:countries[i]
});
}
for (var i = 0; i < countries.length; i++) {
data.push({
id:i,
country: countries[i],
downloads: Math.round(Math.random() * 20000),
sales: Math.random() *...