ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

ng-src in cellTemplate

Open flex123 opened this issue 11 years ago • 15 comments

Hello,

I'm using a cellTemplate with ng-src in an image tag. I noticed some strange behavior when scrolling vertically. Plunker: http://plnkr.co/edit/WxxRyy9v2IXOTZ5Qg36x?p=preview

After scrolling all the way to the bottom and then scrolling up slowly, images suddenly appeared on "Image 12" and "Image 13" even though these 2 entries should not have any image associated to them.

image

flex123 avatar Feb 01 '15 01:02 flex123

It is very unusual. It looks like what it's doing is that as we scroll we create (reuse) the dom elements. At the point we generate the DOM element, we're evaluating your template:

  "cellTemplate":"<div class=\"ui-grid-cell-contents ng-scope ng-binding\"><img ng-src=\"{{COL_FIELD}}\" border=\"0\" width=\"25\">"

I sort of feel like the {{COL_FIELD}} isn't quite right in an ng-src. What that should do is get replaced with grid.getCellValue(row, col), which you can see it is doing if you take the {{}} off the template. But it's kinda funny having a binding in an angular directive, it feels wrong but I can't articulate why it is wrong.

It feels more intuitive to me to go with a template of:

"cellTemplate":"<div class=\"ui-grid-cell-contents ng-scope ng-binding\"><img src=\"{{COL_FIELD}}\" border=\"0\" width=\"25\">"

which gives less funny scroll behaviour, but for me it's now not rendering image1 at all. Not sure why that is either. http://plnkr.co/edit/WxxRyy9v2IXOTZ5Qg36x?p=preview

Does that give you any hints to help progress? In looking at the element for image1, it appears to have a size of 0x0 pixels, but is actually there. Perhaps that's a different problem?

PaulL1 avatar Feb 02 '15 07:02 PaulL1

I started out with "src" instead of "ng-src" but that gave me a different issue.

image

I guess the error occurred because some of the rows do not have a value for image url (e.g. Image 4 onwards). Using "ng-src" seems to have fixed the issue but I ran into the scroll issue.

flex123 avatar Feb 02 '15 15:02 flex123

:+1: issue_2682

I have the same issue with ng-class : expressions are not synchronized with the entity row.

    <li ng-class='triangle c-etat{{row.entity.etat}}'">

mmouterde avatar Feb 05 '15 16:02 mmouterde

  1. Use src="{{ COL_FIELD }}". Using ng-src is causing the binding to not get updated. You're basically stacking two bindings on top of each other.
  2. That image url is serving a 307 redirect to a data url containing a 1x1 pixel image. It does the same thing on codepen: http://codepen.io/anon/pen/NPwgEd

c0bra avatar Feb 06 '15 19:02 c0bra

@mmouterde you don't use curly braces inside most (or all?) ng- directives.

The proper thing would be, I think:

 <li ng-class='triangle c-etat' + row.entity.etat">

or

 <li class='triangle c-etat{{ row.entity.etat }}">

c0bra avatar Feb 06 '15 19:02 c0bra

@c0bra, you are absolutely right ! my mistake.

mmouterde avatar Feb 11 '15 10:02 mmouterde

No worries!

c0bra avatar Feb 12 '15 17:02 c0bra

I'm confused why this got closed. It seems like the initial issue is still outstanding.

danroyo avatar Mar 20 '15 19:03 danroyo

Because the original issue was caused by user error, of a sort. You can't do ng-src="{{xxxx}}", you either do src="{{xxxxx}}", or you do ng-src="xxxxx". It isn't believed to be a grid defect.

PaulL1 avatar Mar 20 '15 19:03 PaulL1

Hi I just trying to show a glyphicon according the valu of a field. I did this in my columnDefs { name: 'has_picture', displayName : 'Has Picture', enableSorting: false, enableColumnMenu : false, enableCellEdit: false, cellTemplate: '

{{grid.appScope.getPictureCellTemplate(row.entity.has_picture, 1)}}
' },

and my getPictureCellTemplate is ` $scope.getPictureCellTemplate = function(value, type) { var html = ''; if (value == 1) { if (type === 1) { html += ''; } else { html += ''; } }

        console.log(html);
        return html;
    }

`

But in the cell, when i run my app the html code (<span class....) is shown...

Any hint to solve this

TIA, Yamil

YamilBracho avatar May 16 '16 14:05 YamilBracho

I solve by myself. I just wrote cellTemplate: '

' + ' ' + ' ' + '
' },

Regards,

YamilBracho avatar May 16 '16 15:05 YamilBracho

Hi guys, I got the same problem. How should I do? I can't use: ng-src="" or src="{{COL_VALUE}}", both takes the: GET http://localhost:7777/grid.getCellValue(row,%20col) 404 (Not Found)

MMrR0b0TT avatar Jun 30 '16 19:06 MMrR0b0TT

I wrote : enableCellEdit: false, cellTemplate: '<div class="ui-grid-cell-contents">' + '<span ng-if="row.entity.has_picture == 1" class="glyphicon glyphicon-picture" data-placement="left" data-toggle="tooltip" title="Has Picture"></span> ' + '<span ng-if="row.entity.has_video == 1" class="glyphicon glyphicon-facetime-video" data-placement="left" data-toggle="tooltip" title="Has video"></span> ' + '<span ng-if="row.entity.has_extras == 1" class="glyphicon glyphicon-asterisk" data-placement="right" data-toggle="tooltip" title="Has Extras"></span> ' + '</div>' }, ...

YamilBracho avatar Jun 30 '16 19:06 YamilBracho

Replacing ng-src="{{xxxxx}}" with src="{{xxxxx}}" worked for me.

alvioshki avatar Sep 06 '16 14:09 alvioshki

Hi YamilBracho, I have the same requirement as your's. Can I have a working code demo of your provided code?

krishna0703 avatar Aug 02 '18 10:08 krishna0703