BootStrap带样式打印
在新窗口打印时bootstrap表格的样式出不来,因为打印时没有加载CSS样式。
我在jquery.PrintArea.js的基础上改造了下打印的方法:
(function ($) {
var printAreaCount = 0;
$.fn.printArea = function () {
var ele = $(this);
var idPrefix = "printArea_";
removePrintArea(idPrefix + printAreaCount);
printAreaCount++;
var iframeId = idPrefix + printAreaCount;
var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
iframe = document.createElement('IFRAME');
$(iframe).attr({
style: iframeStyle,
id: iframeId
});
document.body.appendChild(iframe);
var doc = iframe.contentWindow.document;
$(document).find("link").filter(function () {
return $(this).attr("rel").toLowerCase() == "stylesheet";
}).each(
function () {
doc.write('<link type="text/css" rel="stylesheet" href="'
+ $(this).attr("href") + '" >');
});
doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html()
+ '</div>');
doc.close();
var frameWindow = iframe.contentWindow;
frameWindow.close();
frameWindow.focus();
frameWindow.print();
}
var removePrintArea = function (id) {
$("iframe#" + id).remove();
};
$.fn.printAreas = function () {
var ele = $(this);
winname = window.open('', "_blank", '');
var doc = winname.document;
$(document).find("link").filter(function () {
return $(this).attr("rel").toLowerCase() == "stylesheet";
}).each(
function () {
doc.write('<link type="text/css" rel="stylesheet" href="'
+ $(this).attr("href") + '" >');
});
doc.write($(ele).html());
doc.close();
winname.print();
}
})(jQuery);
前台调用的时候,把table放在一个div里,打印div即可:
<div class="ibox-content" id="divprint">
<table id="tablePrint" class="footable table table-stripped toggle-arrow-tiny" data-page-size="8">
<thead>
<tr>
<th class="text-center">项目</th>
<th class="text-center">部门</th>
<th class="text-center">营业收入</th>
<th class="text-center">利润</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td class="text-center">@item.ProjectName</td>
<td class="text-center">@item.DepartNameS</td>
<td class="text-right"><a onclick="loadDetail('@item.ProjectId','@item.DepartId')">@item.InComeS</a></td>
<td class="text-right"><a onclick="loadProftsDetail('@item.ProjectId','@item.DepartId')">@item.ProfitS</a></td>
</tr>
}
</tbody>
</table>
<div class="dataTables_paginate paging_bootstrap pagination"> </div>
</div>
js调用:
//打印
$("#print").click(function ()
$("#divprint").printAreas();
});
BootStrap带样式打印的更多相关文章
- Bootstrap表格样式(附源码文件)--Bootstrap
1.表格默认样式 <h4>表格默认样式</h4><table><!--默认样式--> <tr><th>序号</th> ...
- [置顶]
bootstrap自定义样式-bootstrap侧边导航栏的实现
前言 bootstrap自带的响应式导航栏是向下滑动的,有时满足不了个性化的需求,需要做一个类似于android drawerLayout 侧滑的菜单,这就是我要实现的bootstrap自定义侧滑菜单 ...
- yii使用bootstrap分页样式
Bootstrap是Twitter推出的一个开源的用于前端开发的工具包.它由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架.Bootstra ...
- android学习笔记50——SQLiteOpenHelper、android实现系统自带样式
SQLiteOpenHelper SQLiteOpenHelper是android提供的一个管理数据库的工具类,可用于管理数据库的创建和版本更新. 一般的用法是创建SQLiteOpenHelper的子 ...
- bootstrap 分页样式代码
bootstrap 分页样式代码,废话不多说,直接上源码 <!DOCTYPE html> <html> <head> <title>Bootstrap ...
- [Bootstrap]全局样式(三)
表格 1.基本类 .table {width/margin-bottom/} {padding/border-top} e.g.:<table class="table" ...
- [Bootstrap]全局样式(二)
具体排版 1.标题和标题类 <h1> ~<h6>和.h1~h6|副标题<small>和.small font-size mar ...
- Android中实现全屏、无标题栏的两种办法(另附Android系统自带样式的解释)
在进行UI设计时,我们经常需要将屏幕设置成无标题栏或者全屏.要实现起来也非常简单,主要有两种方法:配置xml文件和编写代码设置. 1.在xml文件中进行配置 在项目的清单文件AndroidManife ...
- Android自带样式
Android系统自带样式: android:theme="@android:style/Theme.Dialog" 将一个Activity显示为对话框模式 android:the ...
随机推荐
- Hadoop-2.4.1学习之Streaming编程
在之前的文章曾提到Hadoop不仅支持用Java编写的job,也支持其他语言编写的作业,比方Hadoop Streaming(shell.python)和Hadoop Pipes(c++),本篇文章将 ...
- 嵌入web字体
@font-face模块 可以帮助我们轻松解决Web页面中使用优雅字体的方式,而且我们可以根据需要自定义多种字体,但是每个@font-face只能定义一种,若需要多个字体就启用多个@f ...
- javascript Array(数组)
迁移时间:2017年5月25日08:05:33 UpdateTime--2017年3月31日16:29:08 一.数组(Array) (一)用法 //js声明数组的两大类方式 // 第一类(通常使 ...
- 04-hibernate注解-一对一双向外键关联
一对一双向外键 1,主控方的配置同一对一单向外键关联. 2,@OneToOne(mappedBy="card") //被控方 @OneToOne(mappedBy="ca ...
- SSH限制ip登陆
linux限制IP访问ssh 在/etc/hosts.allow输入 (其中192.168.10.88是你要允许登陆ssh的ip,或者是一个网段192.168.10.0/24) sshd: ...
- ElasticSearch「1」本地安裝Elasticsearch 6.0.1 + Elasticsearch-head插件
# 下載包 https://www.elastic.co/downloads/past-releases/elasticsearch-6-0-1 https://github.com/mobz/ela ...
- lucene 分词器
分词器 作用:切分关键词的. 在什么地方使用到了:在建立索引和搜索时. 原文:An IndexWriter creates and maintains an index. 1,切分: An Index ...
- 关闭MongoDB
以下方法干净地关闭MongoDB: 完成所有挂起的操作.刷新数据到数据文件.关闭所有的数据文件 1. > use admin switched to db admin > db.shutd ...
- ExtJS学习------Ext.define的继承extend,用javascript实现相似Ext的继承
(1)Ext.define的继承extend 详细实例: Ext.onReady(function(){ //Sup Class 父类 Ext.define('Person',{ config:{ n ...
- xgboost 自定义目标函数和评估函数
https://zhpmatrix.github.io/2017/06/29/custom-xgboost/ https://www.cnblogs.com/silence-gtx/p/5812012 ...