Demo - Cell Templates

by KirillMetrik

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.grapecity.com/wijmo/5.latest/styles/wijmo.min.css">
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.grid.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/interop/angular/wijmo.angular.min.js"></script>
<!-- mark this as an Angular application and give it a controller -->
<div ng-app="app" ng-controller="appCtrl" class="container">
   
  <wj-flex-grid items-source="data" item-formatter="formatter" format-item="formatProvider(s,e)">
    <wj-flex-grid-column header="Country" binding="country">
      <wj-flex-grid-cell-template 
            cell-type="Cell">
            <img ng-src="http://flagpedia.net/data/flags/mini/{{$item.abb}}.png" />
            {{$item.country}}
        </wj-flex-grid-cell-template>
    </wj-flex-grid-column>
    <wj-flex-grid-column header="Sales" binding="sales" is-read-only="true">
    </wj-flex-grid-column>
    <wj-flex-grid-column header="Expenses" binding="expenses">
    </wj-flex-grid-column>
  </wj-flex-grid>

</div>

CSS

.wj-flexgrid {
  max-height: 350px; 
  margin-top:10px;
}
.wj-cell img {
  width: 30px;
}

JavaScript

// define app, include Wijmo 5 directives
var app = angular.module('app', ['wj']);

// controller
app.controller('appCtrl', function ($scope,$compile) {

    // create some random data
    var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
        abb = 'us,de,gb,jp,it,gr'.split(','),
        data = [];
    for(var j=0; j<1000; j++) {
      for (var i = 0; i < countries.length; i++) {
          data.push({
              country: countries[i],
              abb: abb[i],
              sales: Math.random() * 10000,
              expenses: Math.random() * 5000,
              repeatFlag: Math.random()*10
          });
      }
    }
    
    $scope.formatter=(panel,r,c,cell)=>{
 /*    	if(panel.cellType==wijmo.grid.CellType.Cell&&panel.columns[c].binding=="sales"){
    	        cell.innerHTML="";
    	        var dataItem=panel.rows[r].dataItem;
    	        var temp=`<button ng-click="showMsg('`+dataItem.country+`')">Click me</button>`;
    	        var el=$compile(temp)($scope);
    	        cell.appendChild(el[0]);
    	      } */
    };
    
    $scope.formatProvider=(s,e)=>{
if(e.panel.cellType==wijmo.grid.CellType.Cell&&e.panel.columns[e.col].binding=="sales"){
              e.cell.innerHTML="";
              var dataItem=e.panel.rows[e.row].dataItem;
              var temp=`<button ng-click="showMsg('`+dataItem.country+`')">Click me</button>`;
              var el=$compile(temp)($scope);
              e.cell.appendChild(el[0]);
            }
    }
		
    $scope.showMsg=(country)=>{
    	alert('this is a secret message from '+country);
    }
    // expose data as a CollectionView to get events
    $scope.data = new wijmo.collections.CollectionView(data);
    
    // handle button clicks
    $scope.clickItem = function(country) {
        alert('thanks for selecting ' + country);
    };
});