javascript - Angular Ui-Grid Conditional CellTemplate - Stack Overflow

I need to show a button in my ui-grid as long as the field value is NOT an empty string.I tried using

I need to show a button in my ui-grid as long as the field value is NOT an empty string. I tried using ng-if but it is not working. Here is the code in my grid options:

  { field: 'ReleaseStatus', 
    width: 125, 
    displayName: 'Release Status', 
    cellTemplate: 
    '<div ng-if="row.entity.ReleaseStatus != """>
        <button id="editBtn" 
            type="button" 
            class="btn btn-default"  
            data-toggle="modal" 
            data-target="#myModal" 
            ng-click="grid.appScope.launch(row)">
            {{COL_FIELD}}
        </button>
    </div>'
   },

Without the ng-if the button displays and works great. However, because some records have an empty string for the field ReleaseStatus, the button should not appear.

Any assistance is greatly appreciated.

I need to show a button in my ui-grid as long as the field value is NOT an empty string. I tried using ng-if but it is not working. Here is the code in my grid options:

  { field: 'ReleaseStatus', 
    width: 125, 
    displayName: 'Release Status', 
    cellTemplate: 
    '<div ng-if="row.entity.ReleaseStatus != """>
        <button id="editBtn" 
            type="button" 
            class="btn btn-default"  
            data-toggle="modal" 
            data-target="#myModal" 
            ng-click="grid.appScope.launch(row)">
            {{COL_FIELD}}
        </button>
    </div>'
   },

Without the ng-if the button displays and works great. However, because some records have an empty string for the field ReleaseStatus, the button should not appear.

Any assistance is greatly appreciated.

Share Improve this question edited Nov 4, 2016 at 18:41 Mike 1,6673 gold badges14 silver badges21 bronze badges asked May 19, 2016 at 18:28 Rani RadcliffRani Radcliff 5,0965 gold badges38 silver badges64 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

you should write it this way:

'<div ng-if="row.entity.ReleaseStatus !== \'\'">'

you can also put the ng-if directly on the buttom you are trying to hide.

however be careful of using ng-if because it creates a new scope everytime.

Solution 1: There is a simple way to do this, please have a look on this example.

{
    name: 'nameishere', displayName: 'Display Name', cellTemplate:
       '<div class="ui-grid-cell-contents" ng-if="grid.appScope.haveFile(row.entity.nameishere)"><a href="' + apiURL + '/InvalidFiles/{{row.entity.nameishere}}" download="{{row.entity.nameishere}}" >{{ row.entity.nameishere}}</a></div>'+
       '<div class="ui-grid-cell-contents" ng-if="grid.appScope.haveNotFile(row.entity.nameishere)">{{ row.entity.nameishere}}</div>'
},

and create multiple functions OR use a function with if-else

$scope.haveFile    = function (data) { return data == 'No File to Display' };
$scope.haveNotFile = function (data) { return data != 'No File to Display' };

Solution 2: You should write it this way, string and integer handle in a different way.

cellTemplate:'<div ng-if="row.entity.status !== \'Your String Here\'">'
cellTemplate:'<div ng-if="row.entity.status  !== 23>'

Solution 3: Use ng-if like this

cellTemplate:'<div>{{row.entity.status  == 0 ? "Active" : (row.entity.status  == 1 ? "Non Active" : "Deleted")}}</div>';

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744777788a4593148.html

相关推荐

  • javascript - Angular Ui-Grid Conditional CellTemplate - Stack Overflow

    I need to show a button in my ui-grid as long as the field value is NOT an empty string.I tried using

    8天前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信