easylui 데이터grid 동적 생성 열

7494 단어 datagrid
 1 function load(sdate) {
 2     $.getJSON("workorder/statistics.do", {
 3         sdate : sdate+'-01'
 4     }, function(resp) { // 
 5         var columns = new Array(); // 
 6         var row = resp.rows[0];        // 
 7 
 8         // columns 
 9         $.each(row, function(i, v) {
10             if (i != "username") {
11                 var column = {};
12                 column["title"] = "" + i;// title, 
13                 column["width"] = 25;
14                 column["field"] = "" + i;// field
15                 column["align"] = "center";
16                 column["styler"] = function(value) {
17                     var d = new Date(sdate+'-' + i);
18                     if (d.getDay() == 6 || d.getDay() == 0) {
19                         return "background:#DDD";
20                     }
21 
22                     if (value == 1) {
23                         return "background:#CCFF33";
24                     }
25 
26                 };
27                 column["formatter"] = function(value) {
28                     return " ";
29                 };
30                 columns.push(column);// 
31             }
32         });
33 
34         // datagrid
35         $('#statistics').datagrid({
36             toolbar : "#searchBar",
37             rownumbers : true,
38             singleSelect : true,
39             fit : true,
40             striped: true,
41             onSelect : function(rowIndex) {
42                 $(this).datagrid("unselectRow", rowIndex);
43             },
44             frozenColumns : [ [ {
45                 title : ' ',
46                 field : 'username',
47                 width : 60,
48                 align : "center"
49             } ] ],
50             columns : [ [ {
51                 colspan : columns.length,
52                 title : "<b>"+sdate+"    </b>"
53             } ], columns ]
54         }).datagrid("loadData", resp.rows);// 
55     });
56 }

좋은 웹페이지 즐겨찾기