easyui dataGrid 動態添加列


其實很簡單.
新手創作,不好勿噴.
jsp頁面:

 1 <script>
 2     $(function () {
 3 
 4         $.getJSON('${pageContext.request.contextPath}/resources/json/datagrid_data.json',function(result){
 5             var columns=new Array();
 6             $.each(result.headers[0], function(i, field){
 7                 var column={};
 8                 column["title"]=i;
 9                 column["field"]=field;
10                 column["width"]=50;
11                 columns.push(column);//當需要formatter的時候自己添加就可以了,原理就是拼接字符串.
12             });
13             $('#tt').datagrid({
14                 title:' XXX公司價差補差分配表',
15                 height:500,
16                 singleSelect:true,
17                 url:'',
18                 frozenColumns :[[
19                     {field:'name',title:'項目',width:80,sortable:true,align:'center'},
20                     {field:'count',title:'合計',width:150,sortable:true}
21                 ]],columns : [
22                     columns
23                 ],
24                 rownumbers:true}).datagrid('loadData',result.bodys);
25         });
26     })
27 </script>
28 <div title="XXX公司價差補差分配表" fit="true" border="false" style="height: 94%;">
29 <table id="tt"  ></table>
30 </div>

json 代碼格式.我這不用分頁 也就沒有total

{"headers":[
    {"一月份":"Jan","二月份":"Feb"}
],"bodys":[
    {"name":"LNG","count":"50000","Jan":"20000","Feb":"30000"}
]
}


這樣就行了 是不是很簡單........

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM