Skip to content

Commit 7485e6e

Browse files
committed
fix(uiGridCell): re-compile if template changes
As the grid is scrolled horizontally, the column that a cell is bound to changes, and if the cellTemplate of the new column is different, the cell needs to be recompiled. Otherwise it will display with the previous/original cell's template. This change watches the column's cellTemplate and re-compiles on-change. There is perhaps a slight performance hit with different cell templates, as the cells must be emptied and re-compiled on-scroll, but it's not excessive.
1 parent 531e586 commit 7485e6e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/js/core/directives/ui-grid-cell.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@ angular.module('ui.grid').directive('uiGridCell', ['$compile', '$log', '$parse',
66
compile: function() {
77
return {
88
pre: function($scope, $elm, $attrs, uiGridCtrl) {
9-
// If the grid controller is present, use it to get the compiled cell template function
10-
if (uiGridCtrl) {
9+
function compileTemplate() {
1110
var compiledElementFn = $scope.col.compiledElementFn;
1211

12+
compiledElementFn($scope, function(clonedElement, scope) {
13+
$elm.empty().append(clonedElement);
14+
});
15+
}
16+
17+
// If the grid controller is present, use it to get the compiled cell template function
18+
if (uiGridCtrl) {
1319
$scope.getCellValue = uiGridCtrl.getCellValue;
1420

15-
compiledElementFn($scope, function(clonedElement, scope) {
16-
$elm.append(clonedElement);
21+
compileTemplate();
22+
23+
$scope.$watch('col.cellTemplate', function (n, o) {
24+
if (n !== o) {
25+
compileTemplate();
26+
}
1727
});
1828
}
1929
// No controller, compile the element manually

0 commit comments

Comments
 (0)