i am using angular ui grid, there is one column which is getting html string as input, so to display the column value i am using ng-bind-html in cellTemplate(which works fine to display plain inner text), but cellTooltip doesn't work for tooltip(it doesn't), if i use title="{{row.entity.htmlfield}}" in cellTemplate then it shows html string but i need the plain text, how can i achieve this?
what i am using :
$scope.datagrid={
colDefs=[
{
field:'htmlfield',
cellTemplate:'<div title="{{row.entity.htmlfield}}" ng-bind-html="{{row.entity.htmlfield}}"></div>',//html field is expecting html content
cellTooltip:function(row,col){
return row.entity.htmlfield //it doesn't work with cellTemplate//
}
}
]
}
Solution 1:
Remove cellTooltip when you use cellTemplate
You can use a filter like
app.filter('trusted', function ($sce) {
return function (value) {
return $sce.trustAsHtml(value);
}
});
And inside cellTemplate use -
title="{{row.entity.htmlfield | trusted}}"
Solution 2:
You can create a filter on above lines and use it in cellFilter
Tooltips respect the cellFilter, so if you define a cellFilter it will also be used in the tooltip.
Hope this helps!
We can use cellTemplate and cellTooltip like below, for example,
$scope.gridOptions = {
columnDefs: [
{ name: 'name', cellTemplate:"<div class='ui-grid-cell-contents' title='{{grid.appScope.customTooltip(row,col,COL_FIELD)}}'>{{COL_FIELD CUSTOM_FILTERS}}</div>"
}
]
$scope.customTooltip = function (row,col,value) {
console.log(row);
console.log(col);
return value;
}
I have created function for cellTooltip and passed it into title tag, and its working fine. https://plnkr.co/edit/Dcpwy5opZ9BwC8YdWf3H?p=preview
So simple
just remove cellTooltip and add title tag in the cellTemplate div.
{
field:'htmlfield',
cellTemplate:'<div title="{{row.entity.htmlfield}}">{{row.entity.htmlfield}}</div>',
}
I achieved the goal using a custom directive the code for the directive is like
$scope.datagrid={
colDefs=[
{
field:'htmlfield',
cellTemplate:'<tool-tip text="{{row.entity.htmlfield}}"></tool-tip>',//html field is expecting html content, no need to use cellTooltip as it doesn't work//
}
]
}
//create a custom directive to give required feel to your field template//
angular.module('app').directive('tooTip',function(){
var linkFunction=function(scope,element,attributes){
scope.text=String(attributes['text']).replace('/<[^>]+>/gm', '');
};
return{
restrict:'E',
template:'<div title="{{text}}">{{text}}</div>',
link:linkFunction,
scope:{}
};
});
Need to change like this
cellTemplate:'<div title="{{row.entity.htmlfield}}">{{row.entity.htmlfield}}</div>'
Original cellTemplate from ui-grid source:
"<div class=\"ui-grid-cell-contents\" title=\"TOOLTIP\">{{COL_FIELD CUSTOM_FILTERS}}</div>"
In this template TOOLTIP and COL_FIELD and CUSTOM_FILTERS are ui-grid macro-s.
I define cellTemplate (only icon), and use cellTooltip (with fields error messages), and to work freely:
columnDefs: [
{
...
cellTemplate: '<span class="glyphicon glyphicon-alert" title="TOOLTIP"></span>',
cellTooltip: function( row, col ) {
return ...;
}
...
}
]
Related
any example of how to use this feature ?
A customized placeholder can be provided by specifying the placeholder option provided to the as-sortable item. placeholder can be both a template string or a function returning a template string. ng-sortable , I have tried to put a template but its not appearing on the placeholder, I want the place holder to be a copy of the dragged item with low opacity.
Thanks,
I used this configuration for the "as-sortable" property
$scope.dragDropMetricsOpts =
{
orderChanged: function( event ){},
containment: "#board",
clone: true,
allowDuplicates: false,
placeholder: function( event ){
return "<div style="background: red;"></div>";
}
};
we are using UI GRID to display data and we are using celltemplate in one column to filter data from ID to employee and we have enabled filters for every column.
sampledata:{ID:1 ,salary:3000,Gender:male}
$scope.gridOptions = {
enableFiltering: true,
data:sampledata,
columnDefs: [{Name:Employeetype, Field:ID,
cellTemplate: '<div class="ngCellText"> {{row.entity.ID | ID2EMp}}</div>'}
{Name: salary, field:salary}
{Name:Gender field:Gender}]
}
my filter is something like below:
app.filter('ID2EMp', function() {
return function(text) {
if (text=='1') {
return 'Employee';
}
if (text=='2')
return 'Contractor';
}
});
so now if try to filter grid using UI GRID text filter it wont work if i Type'Employee'/'Contractor' but it will work if i type '1'/'2'..Can anyone please advise how can i make filter work in this situation where i should be able to filter using EMployee keyword.
Also, is there any other way i can manipulate the data to display cell as Employee if ID=1 using filter but not using celltemplate.i have tried with cellfilter but it doesn't seem to work
You can do that in two way. Both with cellTemplate. First use filter like always, {{field | filter }} or use right condition in ng-if statement.
Edit:
First cellTemplate: '<div>{{row.entity.field | filter }} </div>'
where field is field from variable which you pass to ui-grid as data and filter is just filter.
Second: cellTemplate: '<div ng-if="some_condition">{{row.entity.filed}}</div> where field like in first. And some_condition is a condition statement which rows show.
I've got a ui-grid using the latest version (3.0.0-rc22). In my column definitions, I've setup a cellTemplate to allow linking to a different route. Unfortunately it appears that no matter what I set for cellTooltip, the tooltips don't show up so long as I have a cellTemplate. If I remove the cellTemplate, the tootlips show up perfectly.
Here's what I'm doing:
colDefs: [
{
field: 'site_name',
displayName: 'Site Name',
cellTooltip: function (row, col) {return row.entity.site_name},
filter: { condition: uiGridConstants.filter.CONTAINS },
cellTemplate: siteNameLink,
width: '25%'
},{ ... }
]
I understand that just doing cellTooltip: true wouldn't work because the cellTemplate has HTML in it, but I ought to be able to specify a custom tooltip using the functions on row.entity.site_name, but that doesn't work either.
I've even tried a dumb cellTooltip function like:
function (row, col) { return 'test' }
and no tooltip ever appears. Is there something I'm missing or is this just a missing feature in ui-grid for now?
I'm an idiot. This obviously wouldn't work because the cellTemplate replaces whatever the content is, and cellTooltip is just a title attribute.
Solution is to add the title attribute in the cellTemplate itself like so:
var siteNameLink = '<div class="ui-grid-cell-contents" title="{{COL_FIELD}}"><a
ui-sref="sites.site_card({siteid: row.entity._id})">{{COL_FIELD}}</a></div>';
I'm using the new Angular UI Grid (that is planned to replace ng-grid).
My data needs some formatting before it's displayed in the table. For instance, my server returns an attribute named "status" as a number, but I want to display it as a nice name.
If status=1 display "Todo", if status=2 display "Doing" etc.
How can this be done in UI Grid?
The preferred method now is to use a cellFilter, rather than a custom template. Custom templates are OK, but they impose more workload on upgrade - you have to check whether new features require modifications to your template.
There is a reasonable example of filters in the tutorials: http://ui-grid.info/docs/#/tutorial/201_editable
Note the cellFilter: 'mapGender' on the gender column, and the filter itself defined further below in the tutorial:
.filter('mapGender', function() {
var genderHash = {
1: 'male',
2: 'female'
};
return function(input) {
if (!input){
return '';
} else {
return genderHash[input];
}
};
})
First step, add a cellTemplate to the column:
$scope.gridOptions.columnDefs = [
{field:'status', displayName: 'Status',cellTemplate: 'statusTemplate.html'}
];
The Template-File should look like this (COL_FIELD is the actual field):
<div style="text-align: center">{{COL_FIELD==1 ? 'Todo' : 'Doing'"}}</div>
Hope, you got the idea! :)
The shortest way is use CellTemplate with appScopeProvider:
vm.gridOptions = {
columnDefs: [
{
field: 'status',
cellTemplate: '<div>{{grid.appScope.formatStatus(row)}</div>'
}
],
appScopeProvider: {
formatStatus: function (row) {
return row.entity.status === 1 ? 'Todo' : 'Doing';
},
}
}
I am new to angular and ng-grid. I am using ng-grid as grid control in my project. I am trying to edit a cell whose value is formatted with a angular filter. For example:
{field:'rate | currency: "GBP "', displayName:'Rate'}
Here currency filter is applied to Rate column. When I click on the "Rate" column to edit, I get a blank textbox as in editable cell template. I was expecting to see the textbox bound to underlying data, but its not happening. Any idea?
Also, on blur or lost focus on cell, it should get out from editable template, even that is not happening. Anything I am missing?
Here is the plukr to see the problem: http://plnkr.co/edit/W5aViYikZzEGnDPgSI5z
Just use the cellFilter option. Plunker
columnDefs: [
{
field: 'name',
displayName: 'Name',
cellTemplate: 'input-tpls.html'},
{
field:'rate ',
displayName:'Rate',
cellFilter: 'currency'
}
],
app.filter('currency', function () {
return function (input) {
//Do your formatting here.
return "GBP " + input;
};
});