1

I have an Angular Kendo Grid referencing it's options object with k-options and k-rebind...

<kendo-grid k-data-source="data" k-options="options" k-rebind="options"></kendo-grid>

When I change the column titles in the referenced options object the grid doesn't notice the change and therefore doesn't fire k-rebind on the next digest.

How can I get it to watch the options object deeply and notice these important changes?

Working code pen.

hally9k
  • 2,423
  • 2
  • 25
  • 47

1 Answers1

1
 $scope.changeColTitles = function(){
    $scope.a++;
    $scope.b++;
  }

If a scope variable is changed in a controller, the changed value won't be get reflected where ever it is used. A watch must be kept and do the corresponding logic inside.

And for your problem, you don't need to keep either watch. The following line of code should resolve the problem. CodePen is here.

$scope.changeColTitles = function(){
    $scope.options.columns[0].title = 'col ' + ++$scope.a;
    $scope.options.columns[1].title =  'col ' + ++$scope.b;
  }
Rama Rao M
  • 2,961
  • 11
  • 44
  • 64
  • Plus a point for working solution but I don't understand your explanation very well... Could you clarify? – hally9k Oct 06 '15 at 03:53
  • Oh sorry for that!. Usually if a scope variable is changed, the angular digest cycle will reflect the value in the view only but in controller it only checks if the variable has any watch to be executed... So in your case: when ever *a* and *b* are changed, that changed values are not really got reflected into columns directly: You can update those columns in two ways, first one is the way I mentioned in the answer and second one is $scope.$watch('a',function(){ }) – Rama Rao M Oct 06 '15 at 04:16
  • You can update those columns in two ways, first one is the way I mentioned in the answer and second one is $scope.changeColTitles = function(){ $scope.a++; $scope.b++; } $scope.$watch('a',function(){ $scope.options.columns[0].title = 'col ' + $scope.a; }) $scope.$watch('b',function(){ $scope.options.columns[0].title = 'col ' + $scope.b; }) I hope that I m clear somewhat! – Rama Rao M Oct 06 '15 at 04:23
  • You should edit your answer rather than put code snippets into your comments... It's illegible on a phone for example. – hally9k Oct 06 '15 at 04:28