kendo-labs / angular-kendo

A project to create a robust set of Angular.js bindings for Kendo UI widgets
474 stars 209 forks source link

Add behavior to component (grid) with angular directives #405

Open mikehaas763 opened 8 years ago

mikehaas763 commented 8 years ago

I'm trying to supplement a kendo component by creating my own directive that I can add as an attribute to the kendo directive. In my situation I'd like to add my own directive to the kendo-grid element I'm using. The hard part is finding a proper way to get a reference to the grid in that directive or its element. All I'm trying to do is add a click handler to the header of the expand collapse detail column so that I can implement a "expand all" feature.

The most straight forward way would be if I could hook into some event from the $element that angular passes into my directive which fires once the grid is rendered.

Hopefully this snippet explains what I'm trying to do:

    angular.module('mod')
        .directive('kendoExpandAll', kendoExpandAll);

    function kendoExpandAll() {
        return {
            scope: {},
            controller: KendoExpandAll,
            controllerAs: 'KendoExpandAll',
            bindToController: true,
        };
    }

    KendoExpandAll.$inject = ['$element'];
    function KendoExpandAll($element) {
            // somehow get an instance of the kendo grid that this directive has been added to
            var expandHeaderJqElement = kendoGridInstance.thead.find('.k-hierarchy-cell.k-header');
            expandHeaderJqElement.on('click', toggleExpandAll.bind(kendoGridInstance));
    }
leblancmeneses commented 8 years ago

$element.data('kendoGrid') I have a util method to poll until data is available on .data('kendoGrid') or any kendo control.

 restrict: 'A',
//scope:{}
 controller: ...