Hello everyone, Today I am going to share a
article about "no record found message" in angularjs ng-grid and ui-grid etc.
The live demo go to link http://embed.plnkr.co/Jj5sfS/preview
In the below example, we are going to explain over
ui-grid for "No Record Found Message" as given below.
The Reference files
The AngularJs code-sample
var app =
angular.module('uigridApp',
['ui.grid',
'ui.grid.selection', 'ui.grid.exporter']);
app.controller("uigridCtrl", function ($scope, $http) {
$scope.getJSONData = function () {
$http.get('JSONdata.json')
.success(function (data) {
$scope.users = data;
});
};
$scope.uiGridOptions = {
data: 'users',
columnDefs: [{
field: 'name'
}, {
field: 'gender',
}, {
field: 'company'
}]
};
$scope.users = {
"data": []
};
$scope.Clear = function () {
$scope.users = {
"data": []
}
};
});
The HTML code-sample
<div ng-app="uigridApp">
<div ng-controller="uigridCtrl">
<h1>In Angular UI Grid,
Display No Records Found </h1>
<div>
<input type="button" style="color:red;" value="Click to Get
Users"
ng-click="getJSONData()" />
<input type="button" style="color:red;" value="Clear
Users"
ng-click="Clear()" />
</div>
<h3>User List</h3>
<div ui-grid="uiGridOptions" ui-grid-selection class="gridHeight">
<div ng-if="users.data.length==0">
<span style="color:red;">No Records Found.</span>
</div>
</div>
</div>
</div>
The CSS code-sample
.gridHeight {
height: 30px;
}
The Full Live demo code-sample
<html>
<head>
<link rel="stylesheet" href="http://ui-grid.info/release/ui-grid-unstable.css" type="text/css">
<style type="text/css">
.gridHeight {
height: 30px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script src="http://ui-grid.info/release/ui-grid-unstable.js"></script>
<script>
var app =
angular.module('uigridApp',
['ui.grid',
'ui.grid.selection', 'ui.grid.exporter']);
app.controller("uigridCtrl", function ($scope, $http) {
$scope.getJSONData = function () {
$http.get('JSONdata.json')
.success(function (data) {
$scope.users = data;
});
};
$scope.uiGridOptions = {
data: 'users',
columnDefs: [{
field: 'name'
}, {
field: 'gender',
}, {
field: 'company'
}]
};
$scope.users = {
"data": []
};
$scope.Clear = function () {
$scope.users = {
"data": []
}
};
});
</script>
</head>
<body ng-app="uigridApp">
<div ng-controller="uigridCtrl">
<h1>In Angular UI Grid,
Display No Records Found </h1>
<div>
<input type="button" style="color:red;" value="Click to Get
Users"
ng-click="getJSONData()" />
<input type="button" style="color:red;" value="Clear
Users"
ng-click="Clear()" />
</div>
<h3>User List</h3>
<div ui-grid="uiGridOptions" ui-grid-selection class="gridHeight">
<div ng-if="users.data.length==0">
<span style="color:red;">No Records Found.</span>
</div>
</div>
</div>
</body>
</html>
The
output go to link http://embed.plnkr.co/Jj5sfS/preview
In the below
images, We see the no record found message when users data length is zero or
null and after click on get users button get the data of users and bind the
data in ui grid and display data. i.e.