雅星娱乐:jqgrid 表格数据导出实例

时间: 作者:按七

  

[jqgrid,表格数据]jqgrid 表格数据导出实例

  

首先,是一段javascript脚本:  
代码如下:

  
/**  
*  
*  
* @param table_id 表格的id  
* @param container_id 容器的id  
* @param form_id 提交表单的id  
* @param title 文件名  
* @param rownumbers  
*/  
function getXlsFromTbl(table_id, container_id ,form_id, title, rownumbers) {  
try {  
var content = "";  
  
  
if (table_id != null && table_id != "" && table_id != "null") {  
content = getTblData($('#' + table_id), $('#' + container_id), rownumbers);  
}  
if (content == "") {  
alert("表格不存在");  
return;  
}  
var fileName = getExcelFileName(title);  
  
doFileExport($('#' + form_id), fileName, content);  
}  
catch (e) {  
alert("导出异常:" + e.name + "->" + e.description + "!");  
}  
}  
function getTblData(tableobj, containerobj, rownumbers) {  
  
  
var outStr = "";  
if (tableobj != null) {  
var rowdata = tableobj.getRowData();  
var Lenr = 1;  
  
  
for (i = 0; i < Lenr; i++) {  
//var Lenc = curTbl.rows(i).cells.length;  
var th;  
if (rownumbers == false) {  
th = containerobj.find('TH:not(:first-child)');  
}  
else {  
th = containerobj.find('TH');  
}  
th.each(function(index, element) {  
var j = index + 1;  
var content = $(element).text();  
content = content.replace(/(^\s*)|(\s*$)/g, "");//去掉空格  
outStr += content + ",";  
});  
outStr += "+nl+";  
}  
var tmp = "";  
for (i = 0; i < rowdata.length; i++) {  
var row = eval(rowdata[i]);  
for (each in row) {  
var temp = $(row[each]).text();  
if($(row[each]).text() == null || $(row[each]).text() == ""){  
if(row[each].charAt(0) != '<')  
outStr += row[each] + ",";  
  
}  
else  
outStr += $(row[each]).text() + ",";  
}  
outStr += "+nl+";  
}  
}  
else {  
outStr = null;  
alert(inTbl + " null!");  
}  
return outStr;  
}  
function getExcelFileName(title) {  
var d = new Date();  
var curYear = d.getYear();  
var curMonth = "" + (d.getMonth() + 1);  
var curDate = "" + d.getDate();  
var curHour = "" + d.getHours();  
var curMinute = "" + d.getMinutes();  
var curSecond = "" + d.getSeconds();  
if (curMonth.length == 1) {  
curMonth = "0" + curMonth;  
}  
if (curDate.length == 1) {  
curDate = "0" + curDate;  
}  
if (curHour.length == 1) {  
curHour = "0" + curHour;  
}  
if (curMinute.length == 1) {  
curMinute = "0" + curMinute;  
}  
if (curSecond.length == 1) {  
curSecond = "0" + curSecond;  
}  
var fileName = title + "_" + curYear + curMonth + curDate + "_"  
+ curHour + curMinute + curSecond + ".csv";  
  
  
return fileName;  
}  
function doFileExport(formobj, filename, content) {  
formobj.html("");  
$("#filename").val(filename);  
$("#content").val(content);  
formobj.submit();  
}  

  

  

  

接着是页面调用的javascript:  
代码如下:

  
  
  

  

代码如下: (责任编辑:admin)

推荐图片Related

相关文章Related

查看更多热门新闻


首页 | js代码 | jQuery特效 | 其他代码 | 关于我们

Copyright © 2010-2019 菲娱国际平台 版权所有

系统要求:本站自适应各终端浏览器分辨率

请使用Google、Firefox、IE9、百度浏览器登录网站

网站地图 | RSS订阅 | 菲娱国际平台