Consider the following snippet of angularJs code:
var myHeaderCellTemplate = \'
Did something like this in Java(backend):
public static String generateHeaderCellTemplate(List<String> excelFields) {
String headerCellTemplate = "{ \"data\": \"myData\", \"columnDefs\": [";
for (int i = 0; i < 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 the output of generateHeaderCellTemplate()
List<String> excelFields
has all the column names groupped together