Reputation: 7843
this follows directly on from this question (with an additional question hence I thought should be a new post?)
The link above shows how to get a grid instance in Angular (thanks to Lars)
So, following on from this last example, I now have added the following directive..
<body>
<div data-ng-app="app">
<div data-ng-controller="Grid as vm">
<div id='aa'>
<div pckendo id='bb' kendo-grid='grid'
k-options="vm.options"></div>
</div>
</div>
</div>
</body>
and in the .js added
angular
.module("app", ["kendo.directives"])
.controller("Grid", Grid)
.directive('pckendo', PCKendo);
....
function PCKendo() {
function link(scope, element, attrs) {
var instance = element;
var vm = scope.vm;
vm.msg = "";
var grid = scope.grid;
}
return {
link: link
}
See here for full example.
Rather than getting the instance in the controller, I would like to get it via a directive (as from what I understand this is a better place to do event handling etc)
I have tried a few things in there, but haven't been able to get the grid instance, so any further help here would be great.
Thanks in advance!
Upvotes: 0
Views: 1225
Reputation: 18402
Basically you do the same thing; you need to wait for the kendoRendered
event, e.g. like this (note that this example may not conform to angular best practices (re isolate scope etc.)):
function PCKendo($timeout) {
function link(scope, element, attrs) {
scope.$on("kendoRendered", function (e) {
scope.$apply(function () {
scope.vm.setMessage("one col");
scope.grid.hideColumn(1);
});
$timeout(function () {
scope.$apply(function () {
scope.vm.setMessage("all cols");
scope.grid.showColumn(1);
});
}, 2000);
});
}
return {
link: link
}
}
(demo)
Upvotes: 2