easyui的datagrid打印(转)
在使用easyui插件的时候,使用最多的应该是datagrid插件。有时候根据客户需求,可能需要将datagrid内容进行打印,这时候如果直接调用window.print,可能由于easyui的datagrid存在滚动条而导致滚动条其他部分打印不出来的问题。通过百度有编“easyui基于web的打印实现”可以基本实现打印,但是还是存在一些问题,比如多表头情况打印不了,某列有调用脚本的,将会出现undefined等等。
通过修改该文的代码,就可以实现直接使用脚本打印easyui的datagrid内容,代码如下:
print.js
// strPrintName 打印任务名
// printDatagrid 要打印的datagrid
function CreateFormPage(strPrintName, printDatagrid) {
var tableString = '<table cellspacing="0" class="pb">';
var frozenColumns = printDatagrid.datagrid("options").frozenColumns; // 得到frozenColumns对象
var columns = printDatagrid.datagrid("options").columns; // 得到columns对象
var nameList = ''; // 载入title
if (typeof columns != 'undefined' && columns != '') {
$(columns).each(function (index) {
tableString += '\n<tr>';
if (typeof frozenColumns != 'undefined' && typeof frozenColumns[index] != 'undefined') {
for (var i = 0; i < frozenColumns[index].length; ++i) {
if (!frozenColumns[index][i].hidden) {
tableString += '\n<th width="' + frozenColumns[index][i].width + '"';
if (typeof frozenColumns[index][i].rowspan != 'undefined' && frozenColumns[index][i].rowspan > 1) {
tableString += ' rowspan="' + frozenColumns[index][i].rowspan + '"';
}
if (typeof frozenColumns[index][i].colspan != 'undefined' && frozenColumns[index][i].colspan > 1) {
tableString += ' colspan="' + frozenColumns[index][i].colspan + '"';
}
if (typeof frozenColumns[index][i].field != 'undefined' && frozenColumns[index][i].field != '') {
nameList += ',{"f":"' + frozenColumns[index][i].field + '", "a":"' + frozenColumns[index][i].align + '"}';
}
tableString += '>' + frozenColumns[0][i].title + '</th>';
}
}
}
for (var i = 0; i < columns[index].length; ++i) {
if (!columns[index][i].hidden) {
tableString += '\n<th width="' + columns[index][i].width + '"';
if (typeof columns[index][i].rowspan != 'undefined' && columns[index][i].rowspan > 1) {
tableString += ' rowspan="' + columns[index][i].rowspan + '"';
}
if (typeof columns[index][i].colspan != 'undefined' && columns[index][i].colspan > 1) {
tableString += ' colspan="' + columns[index][i].colspan + '"';
}
if (typeof columns[index][i].field != 'undefined' && columns[index][i].field != '') {
nameList += ',{"f":"' + columns[index][i].field + '", "a":"' + columns[index][i].align + '"}';
}
tableString += '>' + columns[index][i].title + '</th>';
}
}
tableString += '\n</tr>';
});
}
// 载入内容
var rows = printDatagrid.datagrid("getRows"); // 这段代码是获取当前页的所有行
var nl = eval('([' + nameList.substring(1) + '])');
for (var i = 0; i < rows.length; ++i) {
tableString += '\n<tr>';
$(nl).each(function (j) {
var e = nl[j].f.lastIndexOf('_0'); tableString += '\n<td';
if (nl[j].a != 'undefined' && nl[j].a != '') {
tableString += ' style="text-align:' + nl[j].a + ';"';
}
tableString += '>';
if (e + 2 == nl[j].f.length) {
tableString += rows[i][nl[j].f.substring(0, e)];
}
else
tableString += rows[i][nl[j].f];
tableString += '</td>';
});
tableString += '\n</tr>';
}
tableString += '\n</table>'; window.showModalDialog("/print.htm", tableString,
"location:No;status:No;help:No;dialogWidth:800px;dialogHeight:600px;scroll:auto;");
}
print.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>数据打印</title>
<style type="text/css">
body{background:white;margin:0px;padding:0px;font-size:13px;text-align:left;}
.pb{font-size:13px;border-collapse:collapse;}
.pb th{font-weight:bold;text-align:center;border:1px solid #333333;padding:2px;}
.pb td{border:1px solid #333333;padding:2px;}
</style>
</head>
<body>
<script type="text/javascript">
document.write(window.dialogArguments);
window.print();
</script>
</body>
</html>
调用方式如:
<a href="javascript:void(0);" onclick="CreateFormPage('打印测试', $('#grid'));">打印</a>
easyui的datagrid打印(转)的更多相关文章
- EasyUI的DataGrid 打印导出
EasyUI的DataGrid 打印导出 一直在Winform和WPF的项目,偶尔接触Web都是网上下个模板修修改改就成了,学习的不太深入. 今日遇到一个打印导出datagrid的问题,做桌面项目 ...
- easyUI 中datagrid 返回列隐藏方法
easyui的datagrid方法返回的列,有的值不需要显示可以使用hidden(属性进行隐藏) columns : [ [{ field : 'bailClass', title : '类别', w ...
- EasyUI 中 DataGrid 控件 列 如何绑定对象中的属性
EasyUI 中 DataGrid 控件 是我们经常用到的控件之一, 但是 DataGrid 控件 在绑定显示列时却不支持对象属性绑定. 模型如下: public class Manager impl ...
- easyui的datagrid行的某一列添加链接
通过formatter方法给easyui 的datagrid 每行增加操作链接. 效果图 jsp代码: <th field="url" width="100&quo ...
- EasyUI的datagrid分页
EasyUI的datagrid分页 前台代码: <script type="text/javascript"> $(function () { //查询 search( ...
- easyui使用datagrid时列名包含特殊字符导致表头与数据错位的问题
做一个用easyui的datagrid显示数据的功能时发现表格的列头与数据错位了,而且这个现象不总是能重现,一直没搞清楚原因.后来偶然在控制台看出了一点端倪: 推测表头或者单元格的class名应该是用 ...
- 利用Aspose.Cells完成easyUI中DataGrid数据的Excel导出功能
我准备在项目中实现该功能之前,google发现大部分代码都是利用一般处理程序HttpHandler实现的服务器端数据的Excel导出,但是这样存在的问题是ashx读取的数据一般都是数据库中视图的数据, ...
- 修改easyui中datagrid表头和数据不能分开对齐的BUG。
easyui的datagrid中表头和列只能同时全部向左对齐,全部向右对齐或者居中对齐. 有时候有需求,数据向左或向右,表头居中对齐. 在不修改源码的情况下.下面的代码可以实现该功能. 把下面代码放在 ...
- JQuery EasyUI的datagrid的使用方式总结
JQuery EasyUI的datagrid的使用方式总结第一步:添加样式和js脚本在前台添加展示数据表格的table元素 例如: <div> <table id="tt& ...
随机推荐
- Java(异常处理)动手动脑
1>请阅读并运行AboutException.java示例,然后通过后面的几页PPT了解Java中实现异常处理的基础知识. import javax.swing.*; class AboutEx ...
- bootstrap的html模版
<!DOCTYPE html> <html> <head> <title>Bootstrap 模板</title> <meta nam ...
- jQuery Select 自动选择默认值
////// the Select target Auto Select value extension plugin // // ---------------------------------- ...
- .Net Framework运行机制
首先谈谈.net framework的组成 主要是有两大部分组成:CLR(公共语言运行库)和FCL(Framework类库) CLR的主要功能:和Java虚拟机一样也是一个运行时环境,是一个可由多种编 ...
- Hadoop入门之安装配置(hadoop-0.20.2)
Hadoop,简单理解为HDFS(分布式存储)+Mapreduce(分布式处理),专为离线和大规模数据分析而设计. Hadoop可以把很多linux的廉价PC组成分布式结点,然后编程人员也不需要知道分 ...
- 大前端学习笔记整理【一】CSS盒模型与基于盒模型的6种元素居中方案
概览 CSS盒模型,规定了元素框来处理元素的 内容.内边距.边框和外边距的方式 元素部分是指内容部分,也是最实际的内容,包围内容的称之为内边距,内边距外围是边框,边框外围就是外边距:且外边距是透明的, ...
- 图片轮播 js代码
<script type="text/javascript"> //图片轮换 $(function () { //------------------ var sWid ...
- 关于windows下QT以及QT creator的安装
普及 之 windows下qt的安装及配置 qt介绍 : Qt,分为商业.开源两个版本,商业版需要花钱购买license,而开源版本则遵守GPL协议,提供了源码,用户需要自行编译,才能生产动态 ...
- 和以往印象不同的Java
Java编程概述 一个Java源文件至多有一个public类,但是可以有很多class的定义 public static void main (String args[]) public 代表公共的, ...
- beanstalkd----安装启动
1. 安装This is beanstalkd, a fast, general-purpose work queue.See http://kr.github.io/beanstalkd/ for ...