javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -
each grid cell can have more 1 customtemplate loaded. have directive holds watcher on model_col_field
listen cell updates on scroll when dom rows updated , recompile celltemplate
. without watcher , $compile rows repeat on scroll, showing same set of rows.
is there more angular way of approaching or way improve performance?
relevant controller code: create gridoptions.data
& gridoptions.columndefs
:
var customtemp = '<div ng-repeat="opt in grid.appscope.colvalueoptionsmodel" ng-init="tempstring=model_col_field.clazz+opt.key;"><comparison-directive dbo="model_col_field" attobj="opt" fff="grid.appscope.getattributetemplate(tempstring)" /></div>'; $scope.gridoptions.columndefs = [ { name:'yindex',pinnedleft:true,celltemplate: customtemp, displayname:'index'}, { name:'col1',celltemplate: customtemp}, { name:'col2',celltemplate: customtemp},... ];
ui-grid celltemplate directive:
app.directive('comparisondirective', function ($log, $compile) { return { restrict: 'e', replace: true, scope: { dbo:'=', attobj:'=', fff:'&' }, template: '<div ng-init="key = attobj.key;values=dbo.get4(attobj.key); template = attobj.template || fff(tempstring);"><div class="contentdecompressed" customtemp></div></div>', link: function (scope, element, attrs) { scope.$watch('dbo', function(newvalue, oldvalue) { if(newvalue !== oldvalue){ element.html('<div ng-init="key = attobj.key;values=dbo.get4(attobj.key); template = attobj.template || fff(tempstring);"><div class="contentdecompressed" customtemp></div></div>'); $compile(element.contents())(scope); } }); } }; });
directive each template loaded inside each grid cell:-
app.directive('customtemp', function($templatecache, $compile) { return { link: function(scope, element, attrs) { // console.log(scope.template) element.html($templatecache.get(scope.template)); $compile(element.contents())(scope); } } });
Comments
Post a Comment