angular ng-grid conditional cell template value

2.2k views Asked by At

Warning: Novice Programmer! I have my ng-grid

columnDefs: [
            {field:'', displayName:'Article', cellTemplate: TitleColumn2, width: '300px'},...

I'm using a cellTemplate because I don't want to throw the conditional logic in the clean grid.

var TitleColumn2='<div class="ngCellText"><span ng-show="row.entity[\'url\']"><a href="{{row.entity[\'url\']}}">{{row.entity[\'title\']}}</a></span></div>';

In my object the url value be blank or it may have value. If it's blank I just want to display the text value but if it has a value I want to display the etc... I seem to have the show if there's a value bit but how do I show just the title if there's no value (url= "").

So my question surrounds performing equations on what to display vs. performing a conditional class statement. I found answers for conditional classes but for some reason this doesn't seem to work here. Sorry if I'm overlooking the obvious. It would be nice to see an answer there shows the difference between a conditional if/then for a class and a conditional if/then for a span text display. Please....

1

There are 1 answers

0
Richard C On

I answered this myself because if there are other novices out there like myself then maybe this will help you.

The answer was obvious in the end. I was too hung up on trying to grapple with cellTemplate that I missed the fundamental ng syntax.

Please comment if anyone disagrees with this or has a better suggestion.

var TitleColumn2='<div class="ngCellText"><span ng- show="row.entity[\'url\']">
                  <a href="{{row.entity[\'url\']}}">{{row.entity[\'title\']}}</a></span>
                  <span ng-show="!row.entity[\'url\']">{{row.entity[\'title\']}}</span></div>'