var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.edit', 'ui.grid.cellNav', 'ui.grid.validate', 'addressFormatter','ngMaterial','ui.bootstrap']);
angular.module('addressFormatter', []).filter('address', function() {
return function(input) {
return input.street + ', ' + input.city + ', ' + input.state + ', ' + input.zip;
};
});
app.controller('MainCtrl', ['$scope', '$http', '$window', 'uiGridValidateService', '$templateCache', function($scope, $http, $window, uiGridValidateService, $templateCache) {
uiGridValidateService.setValidator('isFuseAlphaNumeric',
function(argument) {
return function(oldValue, newValue, rowEntity, colDef) {
if (!newValue) {
return true; // We should not test for existence here
} else {
if (argument === true) {
var regexp = new RegExp("^[a-zA-Z0-9\\-,\\s]*$");
return newValue.match(regexp);
} else {
return true;
}
}
};
},
function(argument) {
return 'Only Alphanumeric is Allowed.';
}
);
$templateCache.put('ui-grid/cellFuseTooltipValidator',
"<div class=\"ui-grid-cell-contents\" ng-class=\"{invalid:grid.validate.isInvalid(row.entity,col.colDef)}\" tooltip-html-unsafe=\"{{grid.validate.getFormattedErrors(row.entity,col.colDef)}}\" tooltip-enable=\"grid.validate.isInvalid(row.entity,col.colDef)\" tooltip-append-to-body=\"true\" tooltip-placement=\"top\" title=\"TOOLTIP\">{{COL_FIELD CUSTOM_FILTERS}}</div>"
/*
"<div class=\"ui-grid-cell-contents\" ng-class=\"{invalid:grid.validate.isInvalid(row.entity,col.colDef)}\" tooltip-html-unsafe=\"{{grid.validate.getFormattedErrors(row.entity,col.colDef)}}\" tooltip-enable=\"grid.validate.isInvalid(row.entity,col.colDef)\" tooltip-append-to-body=\"true\" tooltip-placement=\"top\" title=\"TOOLTIP\">"+
"<md-tooltip ng-if=\"false\">Play Music</md-tooltip>"+
"{{COL_FIELD CUSTOM_FILTERS}}</div>"
*/
);
$scope.gridOptions = {
enableCellEditOnFocus: true
};
$scope.gridOptions.columnDefs = [{
name: 'id',
enableCellEdit: false,
width: '10%'
}, {
name: 'name',
field: 'name',
displayName: 'Name',
width: '20%',
validators: {
required: true,
isFuseAlphaNumeric: true
},
cellTemplate: 'ui-grid/cellFuseTooltipValidator'
}, {
name: 'gender',
field: 'gender',
displayName: 'Gender',
width: '20%',
validators: {
required: true
},
cellTemplate: 'ui-grid/cellTitleValidator'
}];
$scope.msg = {};
$scope.gridOptions.onRegisterApi = function(gridApi) {
//set gridApi on scope
$scope.gridApi = gridApi;
gridApi.edit.on.afterCellEdit($scope, function(rowEntity, colDef, newValue, oldValue) {
console.log(rowEntity)
console.log('Isvalid:' + rowEntity['$$invalid'+colDef.name]);
});
gridApi.validate.on.validationFailed($scope, function(rowEntity, colDef, newValue, oldValue) {
/* console.log('rowEntity: ' + rowEntity + '\n' +
'colDef: ' + colDef + '\n' +
'newValue: ' + newValue + '\n' +
'oldValue: ' + oldValue);*/
});
};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
.success(function(data) {
data = data.slice(0, 5);
data[3].gender = null;
data.push({
name: null,
gender: null,
id: '5'
});
$scope.gridOptions.data = data;
});
}]);
.grid {
width: 600px;
height: 450px;
}
div.ui-grid-cell-contents.invalid {
box-shadow: inset 0px 0px 3px 1px #ff5555;
}
.tooltip {
position: absolute;
z-index: 1030;
display: block;
font-size: 12px;
line-height: 1.4;
visibility: visible;
filter: alpha(opacity=0);
opacity: 0;
}
.tooltip.in {
filter: alpha(opacity=90);
opacity: .9;
}
.tooltip.top {
padding: 5px 0;
margin-top: -3px;
}
.tooltip.right {
padding: 0 5px;
margin-left: 3px;
}
.tooltip.bottom {
padding: 5px 0;
margin-top: 3px;
}
.tooltip.left {
padding: 0 5px;
margin-left: -3px;
}
.tooltip-inner {
max-width: 200px;
padding: 3px 8px;
color: #fff;
text-align: center;
text-decoration: none;
background-color: #000;
border-radius: 4px;
}
.tooltip-arrow {
position: absolute;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
}
.tooltip.top .tooltip-arrow {
bottom: 0;
left: 50%;
margin-left: -5px;
border-width: 5px 5px 0;
border-top-color: #000;
}
.tooltip.top-left .tooltip-arrow {
bottom: 0;
left: 5px;
border-width: 5px 5px 0;
border-top-color: #000;
}
.tooltip.top-right .tooltip-arrow {
right: 5px;
bottom: 0;
border-width: 5px 5px 0;
border-top-color: #000;
}
.tooltip.right .tooltip-arrow {
top: 50%;
left: 0;
margin-top: -5px;
border-width: 5px 5px 5px 0;
border-right-color: #000;
}
.tooltip.left .tooltip-arrow {
top: 50%;
right: 0;
margin-top: -5px;
border-width: 5px 0 5px 5px;
border-left-color: #000;
}
.tooltip.bottom .tooltip-arrow {
top: 0;
left: 50%;
margin-left: -5px;
border-width: 0 5px 5px;
border-bottom-color: #000;
}
.tooltip.bottom-left .tooltip-arrow {
top: 0;
left: 5px;
border-width: 0 5px 5px;
border-bottom-color: #000;
}
.tooltip.bottom-right .tooltip-arrow {
top: 0;
right: 5px;
border-width: 0 5px 5px;
border-bottom-color: #000;
}
<!doctype html>
<html ng-app="app">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-aria.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-touch.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-animate.js"></script>
<script src="https://cdn.gitcdn.link/cdn/angular/bower-material/v1.0.6/angular-material.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
<script src="http://ui-grid.info/release/ui-grid.js"></script>
<link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css">
<link rel="stylesheet" href="https://cdn.gitcdn.link/cdn/angular/bower-material/v1.0.6/angular-material.css" type="text/css">
<!--<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">-->
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<div ng-controller="MainCtrl">
<div ui-grid="gridOptions" ui-grid-edit ui-grid-cellNav ui-grid-validate class="grid"></div>
</div>
<script src="app.js"></script>
</body>
</html>