0

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

1 Answer 1

0

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);
    }
  };
});
Sign up to request clarification or add additional context in comments.

4 Comments

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 advance
Create function on tooltip e.g. cellTooltip: function(row, col) { return 'Name: ' + row.entity.name + ' Company: ' + row.entity.company; }
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
here is a plunker

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.