一、需求:在我们日常工作的时候,对数据的导出有需求。比如导出JSON、XML、SQL等形式。方便我们日常使用。

二、组件:我们可以使用bootstrap的扩展插件Table Export来实现我们的需求。

官方地址:http://bootstrap-table.wenzhixin.net.cn/zh-cn/extensions/

代码地址:https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/export

效果:

可以选择导出当前页、选中列。所有数据。

选中列导出,有个问题:对于chekbox列 导出的数据有on,目前没有解决。

三:

js导入:

     <!--JAVASCRIPT-->
<script src="/static/js/jquery-2.1.1.min.js"></script> <script src="/static/export/boot/bootstrap-table.min.js"></script>
<script src="/static/export/boot/bootstrap.min.js"></script> <script src="/static/export/boot/bootstrap-table-export.js"></script>
<script src="/static/export/boot/tableExport.js"></script>
<script src="/static/export/boot/ga.js"></script>

因为导出功能是bootstrap  table的功能的扩展。所以需要使用bootstrap table的一些js和css。

css导入:

 <link href="/static/css/bootstrap.min.css" rel="stylesheet">

     <!--Font Awesome [ OPTIONAL ]-->
<link href="/static/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"> <!--Bootstrap Select [ OPTIONAL ]-->
<link href="/static/plugins/bootstrap-select/bootstrap-select.min.css" rel="stylesheet"> <!--Bootstrap Table [ OPTIONAL ]-->
<link href="/static/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet"> <!--X-editable [ OPTIONAL ]-->
{# <link href="/static/plugins/x-editable/css/bootstrap-editable.css" rel="stylesheet">#} <!--Demo [ DEMONSTRATION ]-->
<link href="/static/css/demo/nifty-demo.min.css" rel="stylesheet">

html代码:

                     <div class="panel">
{# <div class="panel-heading">#}
{# <h3 class="panel-title">服务器信息展示</h3>#}
{# </div>#} <!-------------> <div class="panel-body"> <table id="table" data-toggle="table"
data-url="/cmdb_back_data/" data-show-export="true"
data-toolbar="#toolbar"
data-click-to-select="true"
data-checkbox="true"
data-click-to-select="true"
data-show-columns="true"
data-search="true"
data-data-type="json"
data-show-refresh="true"
data-show-toggle="true"
data-show-columns="true"
data-sort-name="id"
data-page-list="[10, 30, 100, All]"
data-page-size=""
{# data-side-pagination="server"#}
data-pagination="true" data-show-pagination-switch="true">
<!--------------->
<div class="container">
{# <h4>数据导出类型</h4>#}
<span id="toolbar" style="display: inline-block">
<select class="form-control">
<option value="">导出当前页数据</option>
<option value="all">导出全部数据</option>
{# <option value="selected">导出选中数据</option>#}
</select>
</span>
</div>
<!--------------->
<thead>
<tr>
{# <th data-checkbox="true" data-select-item-name="选中" ></th>#}
<th data-field="id" data-sortable="true" >ID</th>
<th data-field="docker_ip" data-sortable="true">容器IP</th>
<th data-field="server_ip" data-sortable="true" >服务器IP</th>
<th data-field="department" data-align="center" data-sortable="true" data-sorter="priceSorter">所属部门</th>
<th data-field="app_name" data-align="center" data-sortable="true" >所属应用</th>
<th data-field="app_owner" data-align="center" data-sortable="true" >应用负责人</th>
</tr>
</thead>
</table>
</div>
</div>
<!--===================================================-->

js代码:

         var $table = $('#table');
$(function () {
$('#toolbar').find('select').change(function () {
$table.bootstrapTable('destroy').bootstrapTable({
exportDataType: $(this).val()
});
});
})

注意:bootstrap table实现有2种方法:

1、列中写对应的data属性,比如上面。

2、js实现。

可以看官网:

http://bootstrap-table.wenzhixin.net.cn/zh-cn/getting-started/

如上需要注意:

 data-show-export="true"

或者:

             showExport: true,
exportDataType: "basic",

2种方式添加导出功能!!

bootstrap组件-导出数据的更多相关文章

  1. C#不用COM组件导出数据到Excel中

    <?xml version='1.0'?><?mso-application progid='Excel.Sheet'?><Workbook xmlns='urn:sch ...

  2. 浅谈控件(组件)制作方法一(附带一delphi导出数据到Excel的组件实例)(原创)

    来自:http://blog.csdn.net/zhdwjie/article/details/1490741 -------------------------------------------- ...

  3. 用 NPOI 组件实现数据导出

    利用 Nuget 安装 NPOI 组件. 所需引用的 dll:ICSharpCode.SharpZipLib.dll.NPOI.dll.NPOI.OOXML.dll.NPOI.OpenXml4Net. ...

  4. Excel导出数据Excel.Application组件权限设置方法

    很多网络应用系统都会涉及到数据采用Excel方式导出的模块,部分朋友问我到底怎么弄,其实方式很多种,目前比较优秀的方式还是直接用Excel的Excel.Application方式比较合适. 采用Exc ...

  5. 1.ASP.NET MVC使用EPPlus,导出数据到Excel中

    好久没写博客了,今天特地来更新一下,今天我们要学习的是如何导出数据到Excel文件中,这里我使用的是免费开源的Epplus组件. 源代码下载:https://github.com/caofangshe ...

  6. JS组件系列——Bootstrap组件福利篇:几款好用的组件推荐(二)

    前言:上篇 JS组件系列——Bootstrap组件福利篇:几款好用的组件推荐 分享了几个项目中比较常用的组件,引起了许多园友的关注.这篇还是继续,因为博主觉得还有几个非常简单.实用的组件,实在不愿自己 ...

  7. bootstrap学习笔记--bootstrap组件

    前面已经学习了bootstrap环境搭建以及基本布局方面的知识,下面将学习下关于bootstrap的相关组件,知识点有点多. 关于bootstrap组件知识点目录: Bootstrap--代码显示 B ...

  8. MVC导出数据到EXCEL新方法:将视图或分部视图转换为HTML后再直接返回FileResult

    导出EXCEL方法总结 MVC导出数据到EXCEL的方法有很多种,常见的是: 1.采用EXCEL COM组件来动态生成XLS文件并保存到服务器上,然后转到该文件存放路径即可: 优点:可设置丰富的EXC ...

  9. ASP.NET MVC使用Bootstrap系列(3)——使用Bootstrap 组件

    阅读目录 Bootstrap 导航条 列表组 徽章 媒体对象 页头 路径导航 分页 输入框组 按钮式下拉菜单 警告框 进度条 小结 Bootstrap为我们提供了十几种的可复用组件,包括字体图标.下拉 ...

随机推荐

  1. Codeforces 981H:K Paths

    传送门 考虑枚举一条路径 \(u,v\),求出所有边经过它的答案 只需要求出 \(u\) 的子树内选出 \(k\) 个可以重复的点,使得它们到 \(u\) 的路径不相交 不难发现,就是从 \(u\) ...

  2. 正能量:You Are the Best

    Success comes from knowing that you did your best to become the best that you are capable of becomin ...

  3. OpenGL学习--03--矩阵

    Model--View--Projection 1.tutorial03.cpp // Include standard headers #include <stdio.h> #inclu ...

  4. Android 通过URL获取网络资源

    1.先在AndroidManifest.xml中注册加入访问因特网服务的权限: <uses-permission android:name="android.permission.IN ...

  5. xxxx签名算法逆向&&python脚本实现

    前言 有一段时间没看安卓了,找几个软件练练手. 这是一个考驾照用的 app. 官方网址: http://www.******baodian.com/ 本文就分析一下在 重置密码时对 数据包 进行签名来 ...

  6. maven 骨架命令行创建

    项目的骨架maven 约定在项目的根目录下放置pom.xml,在src/main/java目录下放置主代码,在src/test/java下放置项目的测试代码. 这些基本的目录结构和pom.xml文件的 ...

  7. easyui 笔记

    easyui-datagrid:loadFilter:处理服务器端传递过来的参数. 刷新datagrid:$("#xxx").datagrid('reload'): form 表单 ...

  8. Django基本设置

    Dango设置流程图片示例: 设置路由时需要注意的一个点是:Django中定义路由时,通常习惯以斜线 / 结尾 其他常用命令: python manage.py runserver 0.0.0.0:8 ...

  9. zabbix系列之八——安装后配置三Triggers

    1Triggers(触发器) 描述 详细 备注 术语描述 1)触发器是评估监控项采集的数据的逻辑表达式,代表了当前系统状态. 2)触发器可定义一个什么数据是可接受的阈值,因此,如果接收的数据超过了可接 ...

  10. Sun Solairs系统添加裸设备

    Sun Solaris系统添加裸设备对表空间进行扩容的大体操作步骤. 1.查看当前卷组信息 --查看当前卷组信息#vxdg list --查看当前卷组中物理磁盘的使用情况#vxdg free |gre ...