javascript - Default headerCell Template in ng-grid -


consider following snippet of angularjs code:

var myheadercelltemplate = '<div class="ngheadersortcolumn {{col.headerclass}}" ng-style="{\'cursor\': col.cursor}" ng-class="{ \'ngsorted\': !nosortvisible }">' +                            '<div ng-click="col.sort($event)" ng-class="\'colt\' + col.index" class="ngheadertext">{{col.displayname}} <img src="plus-icon.png" /></div>' +                            '<div class="ngsortbuttondown" ng-show="col.showsortbuttondown()"></div>' +                            '<div class="ngsortbuttonup" ng-show="col.showsortbuttonup()"></div>' +                            '<div class="ngsortpriority">{{col.sortpriority}}</div>' +                            '<div ng-class="{ ngpinnedicon: col.pinned, ngunpinnedicon: !col.pinned }" ng-click="togglepin(col)" ng-show="col.pinnable"></div>' +                            '</div>' +                            '<div ng-show="col.resizable" class="ngheadergrip" ng-click="col.gripclick($event)" ng-mousedown="col.griponmousedown($event)"></div>'; $scope.gridoptions = {     data: self.mydata,     columndefs: [         { field: 'firstfield', displayname: 'first column', headercelltemplate: myheadercelltemplate },         { field: 'secondfield', displayname: 'second column', headercelltemplate: myheadercelltemplate },         { field: 'lastfield', displayname: 'last column', headercelltemplate: myheadercelltemplate }     ] }; 

i trying display excel in browser using ng-grid. need headercelltemplate common fields. since fields coming excel, can random, dynamic , number.

how set default headercelltemplate fields, not have mention fields in columndefs section of gridoptions? (since fields uncontrolled)

p.s. refer this question asked me well. reason can't use template on row, because want fields individually draggable.

did in java(backend):

public static string generateheadercelltemplate(list<string> excelfields) {          string headercelltemplate = "{ \"data\": \"mydata\", \"columndefs\": [";         (int = 0; < excelfields.size(); i++) {             string field = excelfields.get(i);             if (i != 0) {                 headercelltemplate += ",";             }             headercelltemplate += ("{ \"field\": \"" + field);             headercelltemplate += ("\", \"width\":80," + " \"headercelltemplate\":" + "\"myheadercelltemplate\"}");         }         headercelltemplate += "]}";         return headercelltemplate;     } 

controller:

@requestmapping(value= "/myheadercelltemplate", method= requestmethod.get)     public @responsebody string headertemplate() {         return "<div class=\"ngheadersortcolumn {{col.headerclass}}\" ng-style=\"{cursor: col.cursor}\" ng-class=\"{ ngsorted: !nosortvisible }\">"+                 "<div class=\"ngheadertext item\" id=\"{{col.displayname}}\" draggable value=\"{{col.displayname}}\">{{col.displayname}}</div>"+                 "<div class=\"ngsortbuttondown\" ng-show=\"col.showsortbuttondown()\"></div>"+          "<div class=\"ngsortbuttonup\" ng-show=\"col.showsortbuttonup()\"></div>"+         "<div class=\"ngsortpriority\">{{col.sortpriority}}</div>"+         "</div>"+  "<div ng-show=\"col.resizable\" class=\"ngheadergrip\" ng-click=\"col.gripclick($event)\" ng-mousedown=\"col.griponmousedown($event)\"></div>";     } 

app.js:

    $scope.mydata = excelasjson.exceldata;     $scope.coldefs = columndefsjson.columndefs;     $scope.gridoptions = { data: 'mydata', columndefs: 'coldefs'}; 

where $scope.coldefs contains output of generateheadercelltemplate() list<string> excelfields has column names groupped together


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -