使用 datagrid-export.js 插件导出数据表格时,会将html中定义的datagrid所有定义的字段全部导出。

如:

 1 $(\'#test\').datagrid({
 2             url:url,
 3             method: \'post\',
 4             singleSelect:true,//是否单选
 5             pagination:true,
 6             pageSize:30,
 7             rownumbers:true,//是否显示行号
 8             striped:true,//是否开启隔行变色
 9             loadMsg:"加载中...",
10             emptyMsg:"无数据!",
11             toolbar:toolbar,
12             columns:[[
13                 {field:\'id\',title:\'id\',width:60,hidden:true},
14                 {field:\'orgCode\',title:\'test\',width:80,hidden:true},
15                 {field:\'orgName\',title:\'test\',width:200},
16                 {field:\'partyCode\',title:\'test\',width:80,hidden:true},
17                 {field:\'partyname\',title:\'test\',width:200},
18                 {field:\'userName\',title:\'test\',width:80,
19                     formatter: function(value,row,index){
20                         return \'<a href="javascript:;" style="color: #5cb85c; font-weight: bold; margin-left: 5px; text-decoration: none;" title="查看"  onclick="check(\'+index+\')">\'+value+\'</a>\'
21                 }},
22                 {field:\'userAccount\',title:\'test\',width:80},
23                 {field:\'genderId\',title:\'test\',width:80,hidden:true},
24                 {field:\'gender\',title:\'test\',width:80},
25                 {field:\'mobilePhone\',title:\'test\',width:150},
26                 {field:\'partyTypeId\',title:\'test\',width:80,hidden:true},
27                 {field:\'partyType\',title:\'test\',width:80},
28                 {field:\'dateJoinCylc\',title:\'test\',width:180},
29                 {field:\'dateJoinCpcRegular\',title:\'test\',width:180},
30                 {field:\'dateJoinCpc\',title:\'test\',width:180},            
31                 {field:\'createTime\',title:\'test\',width:180}
32             ]]      
33         });    
//导出Excel
$(\'#test\').datagrid(\'toExcel\',\'test.xls\');

导出的Excel表中包含有隐藏的列:id

导出Excel表格:

 

 

如导出的Excel表格不需要隐藏列,可修改datagrid-export.js中toHtml的代码:

 

 

版权声明:本文为xiamengz原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xiamengz/p/12890017.html