How do I add image in a angular ui-grid cell

青春壹個敷衍的年華 提交于 2019-12-21 16:51:14

问题


How do I add image in a angular ui-grid cell.

var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid']);

   app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
     $scope.gridOptions = {
       enableSorting: true,
       columnDefs: [
         { field: 'name' },
         { field: 'company'  },
         { field: 'image'}
       ],
       data:[
         {name:"Name1",company:"Company1",image:"http://cdn.flaticon.com/png/256/70689.png"},
         {name:"Name2",company:"Company2",image:"http://cdn.flaticon.com/png/256/70689.png"},]
   };  
 }]);

回答1:


You can use a custom cell template to render the image in the cell.

var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid']);

app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
  $scope.gridOptions = {
    enableSorting: true,
    rowHeight:100,
    columnDefs: [
      { field: 'name' },
      { field: 'company'  },
      { field: 'image', cellTemplate:"<img width=\"50px\" ng-src=\"{{grid.getCellValue(row, col)}}\" lazy-src>"}
    ],
    data:[
      {name:"Name1",company:"Company1",image:"http://cdn.flaticon.com/png/256/70689.png"},
      {name:"Name2",company:"Company2",image:"http://cdn.flaticon.com/png/256/70689.png"},
      {name:"Name3",company:"Company3",image:"http://cdn.flaticon.com/png/256/70689.png"}
      ]
  };

}]);

Here is a working plnkr.

http://plnkr.co/edit/awQ7B0WmmZhythlCZmgt?p=preview



来源:https://stackoverflow.com/questions/30267172/how-do-i-add-image-in-a-angular-ui-grid-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!