使用CellTemplate和Directive在ng-grid中的单元格中使用jQuery Sparkline

时间:2013-08-10 06:37:24

标签: angularjs directive ng-grid sparklines celltemplate

我正在尝试将ngQuery Sparkline放在ng-grid中的一个单元格中的每一行。该列包含数字数组数据。

Plunkr - > http://plnkr.co/edit/1eNEcx6FQWcJynlVYvFw?p=preview

我正在使用带有单元格模板的指令来实现这一点。

细胞模板:     

指令:

app.directive('ngAge', function() {
  return{
    restrict: 'C',
    replace: true,
    translude: true,
    scope: {ngAgeData: '@'},
    template: '<div>' +
              '<div class="sparklines"></div>' +
                '</div>',
    link: function(scope,element,attrs){
     // var arrvalue= "3386.24000,1107.04000,3418.80000,3353.68000,4232.80000,3874.64000,3483.92000,2735.04000,2474.56000,3288.56000,4395.60000,1107.04000";
     //console.log(attrs.ngAgeData);
     var arrvalue = attrs.ngAgeData;
     var myvalues = new Array();
     myvalues = arrvalue.split(",");
     $('.sparklines').sparkline(myvalues); 

    }
  }
});

我很难在链接函数中获取attrs.ngAgeData值。我不确定我错过了什么。请帮忙!!!

由于

1 个答案:

答案 0 :(得分:2)

使用此celltemplate:

cellTemplate: '<div age-line agedata=row.entity.age></div>'

请注意,值将作为属性传递。

指令应该是:

app.directive('ageLine', function () {
    return {
        restrict: 'A',
        scope: { agedata: '=' },
        link: function (scope, elem) {
            scope.$watch('agedata', function (newval) {
                elem.sparkline(scope.agedata);
            });
        }
    };
});

另请注意,您不需要$。,因为该元素已经是一个jquery(lite)对象。

这是一个工作的掠夺者:http://plnkr.co/edit/oDbPp9DGFCGGZF30Bzsi?p=preview