Angular ui-grid tooltip not displaying - angularjs

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

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);
}
};
});

Related

ui grid 400 error in chrome dev tools when loading image in celltemplate

Has anyone seen this problem and know what's going on? If you load this with chrome dev tools open you will see a 400 error ( Bad Request )
http://plnkr.co/edit/fRhBgC4SmPYL8udb007y?p=preview
The problem appears when you use an row.entity.imgurl inside the cellTemplate.
var testApp = angular.module('testApp', ['ui.grid']);
testApp.controller('TestCtrl', function($scope) {
$scope.grid = {
rowHeight: 50,
data: [{
name: 'Test',
label: 'Suwako Moriya',
imgurl: 'http://i.imgur.com/945LPEw.png'
}],
columnDefs: [
{ field: 'name'},
{ field: 'label', displayName: 'Name',
cellTemplate: '<div class="ui-grid-cell-contents" title="TOOLTIP"><img alt="{{COL_FIELD CUSTOM_FILTERS}}" src="{{row.entity.imgurl}}"/>'
}
]};
});
You can use:
ng-src="{{row.entity.imgurl}}"

What is the simplest way to turn off three-state column sorting?

What is the simplest way to turn off three-state column sorting for angular UI grid? The third 'unknown' state is very confusing.
UI-grid sortings example: http://ui-grid.info/docs/#/tutorial/102_sorting by default has three sorting states. What I need is to have one column in a default sorting state (ASC or DESC). On click event ui-grid should result into ASC or DESC state, but not the third one "Undefined".
This is UI Grid v3.1.0
Grid UI v3.1.0 can set sortDirectionCycle for each column separately:
$scope.GridOptions.columnDefs: [{
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC]
},
{ sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC] },
{ sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC] },
//... for each
];
Used sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC] to each column worked fine...
var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.resizeColumns', 'ui.grid.moveColumns']);
app.controller('MainCtrl', ['$scope', '$http', 'uiGridConstants', function ($scope, $http, uiGridConstants) {
$scope.gridOptions = {
enableSorting: true,
enableColumnMenus : false,
columnDefs: [
{ field: 'name', width: '33%', minWidth: 150, width: 250,sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC]},
{ field: 'gender', width: '33%', maxWidth: 200, minWidth: 70,sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC] },
{ field: 'company', width: '33%',sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC] }
]
};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
.success(function(data) {
$scope.gridOptions.data = data;
});
}]);

Angular UI Grid - Custom Header Template and Filtering

I'm looking for a good example of having a basic filter and having a custom template. I'm having trouble finding a good example on the tutorial sites. See attached plunk where I'm setting filtering and having a custom header template. Does the filtering need to be embedded into the header template?
http://plnkr.co/edit/VMETPu30iiFc3GYmZZRS?p=preview
var app = angular.module('app', ['ngAnimate', 'ui.grid']);
app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.columns = [{ field: 'name', headerCellTemplate: '<div class="grand-total">Name</div>' }, { field: 'gender' }];
$scope.gridOptions = {
enableSorting: true,
columnDefs: $scope.columns,
enableFiltering: true
};
$scope.remove = function() {
$scope.columns.splice($scope.columns.length-1, 1);
}
$scope.add = function() {
$scope.columns.push({ field: 'company', enableSorting: false });
}
$scope.splice = function() {
$scope.columns.splice(1, 0, { field: 'company', enableSorting: false });
}
$scope.change = function() {
$scope.columns = [{ field: 'First', }, { field: 'Second' }, { field: 'third' }];
$scope.gridOptions.columnDefs = $scope.columns;
}
$scope.unsplice = function() {
$scope.columns.splice(1, 1);
}
$http.get('https://rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
.success(function(data) {
$scope.gridOptions.data = data;
console.log(data)
});
}]);
Thanks in advance!
You can create a custom template and add it to your grid.Try this post you can get some ideas.I have updated some of the codes in blog post.you can do something like this.Hope this will help.Code Sample.

AngularJS : angular-ui-grid showing rows based on the condition

I would like my grid to show rows that only matches a creteria. For example i want my grid to show only the rows where name is Brian.
var app = angular.module('app', ['ngAnimate', 'ui.grid']);
app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.myData = [{name: "Brian", code: 50,count:20},
{name: "Jason", code: 43,userid:1},
{name: "Brian", code: 27,userid:10},
{name: "Devon", code: 29,userid:7},
{name: "Kale", code: 34,userid:2}];
$scope.gridOptions = {
enableSorting: true,
data:'myData',
columnDefs: [
{ field: 'name', displayName: 'Name'},
{field: 'code', displayName: 'Code'},
{ field: 'userid', displayName: 'UserId'
}
}
]
};
}]);
how can i accomplish that? Thank you in advance...
One of the work around would be, Instead of passing myData do filter you criteria and then assign that filtered data to new scope variable and assign that inside your gridOptions data field
Code
$scope.filteredData = myData; //make filter your data manually here
$scope.gridOptions = {
enableSorting: true,
data:'filteredData', //passed filtered data here.
columnDefs: [
{ field: 'name', displayName: 'Name'},
{field: 'code', displayName: 'Code'},
{ field: 'userid', displayName: 'UserId'
}
}
]
};
You need to use a filter. You can read about the standard angular filter here. You can read about how to make custom filters here.

ng-grid - editing then updating remote. How?

I am using ng-grid and I am trying to automatically update a single model when data in the grid-table changes. For that I am using the edit module of ng-grid.
This is the code of my controller:
# Define app
app = angular.module("app", ["ng-rails-csrf", "rails", 'ngTagsInput', 'ui.bootstrap', 'ui.grid', 'ui.grid.edit'])
app = angular.module("app")
app.controller "UsersController", ["$scope", "User", ($scope, User)->
$scope.init = ->
User.query({}).then((results)->
console.log results
$scope.gridOptions.data = results
)
$scope.gridOptions =
enableFiltering: true
columnDefs: [
{field: 'id'}
{field: 'email', enableCellEdit: true, type: 'string'}
{field: 'firstName', enableCellEdit: true, type: 'string'}
{field: 'lastName', enableCellEdit: true, type: 'string'}
{field: 'lastName', enableCellEdit: true, type: 'string'}
]
$scope.init()
$scope.$watch 'gridOptions.data', (newValue, oldValue)->
console.log "new value"
console.log newValue
console.log "old value"
console.log oldValue
# FIXME this causes a lot of updates to the remote
, true
]
html:
.users-list
.my-grid ui-grid="gridOptions" ui-grid-edit="ui-grid-edit"
Is there a better way to do it? Like calling an update function whenever one of the model changes?
I'm not sure where you can use angular debounce or how it applies to the model on your grid.
Maybe something like?
<input ng-model="gridOptions.data" ng-model-options="{debounce: {'default': 700} }"/>
With lodash / underscore it looks like.
$scope.$watch('gridOptions.data', _.debounce(function (value) {
$scope.$apply(function(){
...
})
}, 700));

Resources