免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
EasyUI的DataGrid 打印導出

一直在Winform和WPF的項目,偶爾接觸Web都是網上下個模板修修改改就成了,學習的不太深入。

今日遇到一個打印導出datagrid的問題,做桌面項目的打印導出通常我都是直接將數(shù)據(jù)源拿過來放到我的打印導出模塊直接就出來了,但是在web上沒有積累,特別是用了EasyUI的DataGrid,一時不知道如何是好。

遂度娘一翻找到如下解決方案:

1.打印部分

  新增print.js

// strPrintName 打印任務名// printDatagrid 要打印的datagridfunction 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

View Code

  頁面引用print.js并調用

CreateFormPage("datagrid",$("#dg"));

2.導出部分

  新增export.js

View Code

  新增export.aspx后臺

View Code

  export.aspx前臺僅保留

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="export.aspx.cs" Inherits="export" %>

  頁面引用export.js并調用

Export('outputexcel', $('#dg'));

到此我的打印導出功能已經完成,但是有個問題EasyUI1.3.4不支持IE8,這腫么行!果斷換到1.3.2版本測試沒有問題。做web沒多久深感IE瀏覽器兼容性問題太煩,真是各家做各家的產品!讓人不敢踏入Web界啊。

第一次自己寫博客,感謝大家來捧場,謝謝

本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
JQuery EasyUI datagrid 復雜表頭處理
Merge and split table cells with JavaScript
html表單元素的colspan和rowspan
rowspan colspan
Html表格制作及實例
js判斷undefined類型
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服