Default headerCell Template in ng-grid

后端 未结 1 473
忘掉有多难
忘掉有多难 2021-01-28 11:58

Consider the following snippet of angularJs code:

var myHeaderCellTemplate = \'
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-28 12:17

    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 excelFields has all the column names groupped together

    0 讨论(0)
提交回复
热议问题