Consider the following snippet of angularJs code:
var myHeaderCellTemplate = \'
Did something like this in Java(backend):
public static String generateHeaderCellTemplate(List 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 ""+
"{{col.displayName}}"+
""+
""+
"{{col.sortPriority}}"+
""+
"";
}
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
has all the column names groupped together