I'm trying to apply a simple filter on ui-grid cells and add a tooltip to them but it's not working.
The filter is working correctly but not the tooltip. it's only displayed when I remove the filter.
cellFilter: 'number: 2', cellTooltip: 'Custom tooltip - maybe some help text'
here is a plunker with the example I'm talking about.
any help is really apreciated
Add a comment
|
1 Answer
You can fix this issue introducing custom filter - formatNumber to format the number cellFilter: 'formatNumber:2'
with tooltip -
var app = angular.module('app', ['ui.grid', 'ui.grid.edit']);
app.controller('MainCtrl', ['$scope', '$http', function($scope, $http) {
$scope.gridOptions = {
columnDefs: [{
field: 'name'
}, {
field: 'amount',
name: 'Number',
cellFilter: 'formatNumber:2',
cellTooltip: 'Custom tooltip - maybe some help text'
}, {
field: 'amount',
name: 'Currency',
cellFilter: 'formatNumber:2',
cellTooltip: 'Custom tooltip - maybe some help text'
}, ]
};
$http.get('data.json')
.success(function(data) {
$scope.gridOptions.data = data;
});
}]);
app.filter('formatNumber', function() {
return function(input, decimalPlaces) {
if (isNaN(input))
return input;
else {
return input.toFixed(decimalPlaces);
}
};
});
4 Comments
Med
thank you for your solution that fixes my issue, I just updated ` input.toFixed(decimalPlaces);` with ` Number(input).toFixed(decimalPlaces);` however do you have any idea how can I apply a cell template of tooltip for this example. like
cellTemplate: '<div class="grid-tooltip" uib-tooltip="The applied margin for extra revenues is X %" tooltip-placement="top" tooltip-append-to-body="true"><div class="ui-grid-cell-contents" >{{grid.getCellValue(row, col)}}</div></div>'
and keep the filter working? Thank you in advanceSumit Deshpande
Create function on tooltip e.g. cellTooltip: function(row, col) { return 'Name: ' + row.entity.name + ' Company: ' + row.entity.company; }
Med
I mean applying something like this
cellTemplate: '<div class="grid-tooltip" tooltip="{{ row.entity.state }}" tooltip-placement="top" tooltip-append-to-body="true"><div class="ui-grid-cell-contents">{{ COL_FIELD }}</div></div>'
that will allow me to use uib-tooltip for the tooltip