bootstrapTable printThis打印插件 中 printThis.js中的一个buge

printThis打印插件还有一个大坑,先看看,一定要注意:

如果你用的开发工具(HBuilder.exe)访问形式是ip的形式如:http://127.0.0.1:8020/TestBootStrap11/index.html;打印的时候带数据样式,

但是,如果你在本地打开index.html,访问地址:file:///E:/EhtmlWorking/TestBootStrap11/index.html,再去打印数据就没有样式了;

这是因为打印插件中引入css样式的方式是http://ip:port/projectName/css/bootstrap-table.css的形式;//ip:ip地址,port:端口号,projectName:项目名,css:css文件夹

例如:printThis.js中的代码: baseURL = document.location.protocol + '//' + document.location.host;

不要在本地直接打开测试兼容性,css样式不会被引入;


bootstrapTable printThis打印插件 具体怎么用就不说了,可以参考这个地址: http://www.cnblogs.com/gzcblogs/p/7799621.html

但是你会发现,打印数据的样式怎么也加不上,解决方式用两种:

第一种:(推荐此种方式):

① 修改printThis.js 的 importCSS ,属性值设为 false; 例如

// defaults
    $.fn.printThis.defaults = {
        debug: false,           // show the iframe for debugging
        importCSS: false,        // import parent page css
        importStyle: false,     // import style tags
        printContainer: true,   // print outer container/$.selector
        loadCSS: "",            // load an additional css file - load multiple stylesheets with an array []
        pageTitle: "",          // add title to print page
        removeInline: false,    // remove all inline styles
        printDelay: 333,        // variable print delay
        header: null,           // prefix to html
        footer: null,           // postfix to html
        formValues: true,       // preserve input/form values
        canvas: false,          // copy canvas content (experimental)
        base: false,            // preserve the BASE tag, or accept a string for the URL
        doctypeString: '<!DOCTYPE html>', // html doctype
        removeScripts: false,   // remove script tags before appending
        copyTagClasses: false   // copy classes from the html & body tag
    };

    ②.调用过程如下:(importCSS 属性不要写 或 赋值为 false,不要设置为true,一定要有loadCSS属性)

function printThis(){   //TestBootStrap11 为项目名(记得要加上)

$("#table").printThis({  
           debug: false,  
         
// importCSS:fase,
           importStyle: false,  
           printContainer: true,  
     
     loadCSS: ["TestBootStrap11/css/bootstrap-table.css","TestBootStrap11/css/bootstrap.min.css"],
           pageTitle: "洗衣机统计表",  
           printDelay: 333,
           formValues: false
        });
};

总结:printThis.js 给了两种打印数据带样式的方式:importCSS 和 loadCSS其中importCSS 方式添加样式的引用路径中少了以及项目名

loadCSS是自己添加路径,我在相对路径的基础上加上了项目名(TestBootStrap11,就OK了。



第二种方式就不多说了,指点一下:在printThis.js 找到 它引用的路径,添加上项目名就行了,

获取项目名的方法:

function getProjectName(){
var pathName = document.location.pathname;
return pathName.substring(0,pathName.substr(1).indexOf('/')+1);
}

这时候importCSS 可以用了,printThis.js中的默认样式还改为true;

本人认为在设置属性时二者选其一,都选浪费性能。

经过我对各种前端数据表格的使用,复杂的表头,行分组,小计,合计,导出,打印等功能的实现,推荐使用 bootstrap table 框架



使用bootstrap-table-vue.js在浏览器创建一个表格,你需要按照以下步骤进行操作: 步骤1:引入相关的依赖文件 在HTML文件,需要引入bootstrap、jQuery和bootstrap-table的CSS和JavaScript文件。你可以通过以下方式引入它们: ```html <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-table-vue@1.4.2/dist/bootstrap-table.min.css"> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap-table-vue@1.4.2/dist/bootstrap-table.min.js"></script> ``` 步骤2:创建HTML元素 在HTML文件,创建一个包含表格的元素。例如: ```html <div id="table-container"> <table id="my-table"></table> </div> ``` 步骤3:初始化表格 在JavaScript使用bootstrap-table-vue.js初始化表格。例如: ```javascript $(document).ready(function() { $('#my-table').bootstrapTable({ data: [ {id: 1, name: 'John Doe', age: 25}, {id: 2, name: 'Jane Smith', age: 30}, {id: 3, name: 'Bob Johnson', age: 40} ], columns: [ {field: 'id', title: 'ID'}, {field: 'name', title: 'Name'}, {field: 'age', title: 'Age'} ] }); }); ``` 在这个例子,我们通过`data`属性提供了表格的数据,通过`columns`属性定义了表格的列。 步骤4:运行代码 保存HTML文件,并在浏览器打开它,你将看到一个使用bootstrap-table-vue.js创建的表格。 请注意,以上代码是一个简单的示例,你可以根据自己的需求进行更多的定制和配置。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值