Default headerCell Template in ng-grid

后端 未结 1 476
忘掉有多难
忘掉有多难 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<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

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