Bootstrap表格动态加载内容和排序功能

所属分类:UI-图表,筛选及排序

 91136  544  查看评论 (33)
分享到微信朋友圈
X
Bootstrap表格动态加载内容和排序功能 ie兼容8

安装Bootstrap

我们可以到Bootstrap的官方网站下载Bootstrap的压缩版本,然后引入到我们的项目中,更多细节请参见Bootstrap安装教程,例如下面的代码:

<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>

Table布局

Bootstrap给table提供多个样式的类,你可按照自己的需要添加,例如我编写的表格:

<table class="table table-striped table-bordered" id="example">
    <tr><td></td></tr>
</table>

当然完整的表格肯定不止上面展示内容那么少,但是我们可以添加更多的内容。

接下来是显示网格:定义为数据表控制元素的网格布局,此前我们曾用“span8”元素来表示半宽度的元素,但随着变化的12列在引导我们只需要改变使用“span6”。所以我们的数据表初始化看起来像:

$(document).ready(function() {
    $('#example').dataTable( {
        "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>"
    } );
} );

我们还需要设置一个新的类,以数据表的形式包装元素使元素内联而不是作为一个块(表过滤输入长度选择器是通过这。为此我们只是扩展为DataTable“swrapper”类的选项:

$.extend( $.fn.dataTableExt.oStdClasses, {
    "sWrapper": "dataTables_wrapper form-inline"
} );

Table排序

Bootstrap V2下降支持tablesorter作为表库和结果排序的类已被删除。因此我们需要定义自己的类的造型,我们所能做的一样,我们在做数据表自己的CSS文件(图片中的数据表分布ZIP文件媒体/图像是可用的):

table.table thead .sorting,
table.table thead .sorting_asc,
table.table thead .sorting_desc,
table.table thead .sorting_asc_disabled,
table.table thead .sorting_desc_disabled {
    cursor: pointer;
    *cursor: hand;
}
table.table thead .sorting { background: url('images/sort_both.png') no-repeat center right; }
table.table thead .sorting_asc { background: url('images/sort_asc.png') no-repeat center right; }
table.table thead .sorting_desc { background: url('images/sort_desc.png') no-repeat center right; }
table.table thead .sorting_asc_disabled { background: url('images/sort_asc_disabled.png') no-repeat center right; }
table.table thead .sorting_desc_disabled { background: url('images/sort_desc_disabled.png') no-repeat center right; }

实际上这里我们使用了一个插件,那就是DataTables。


相关插件-图表,筛选及排序

基于echarts双y轴折线图柱状图混合实时更新图

Ets双y轴折线图柱状图混合实时更新图,流畅不卡顿
  图表
 38951  319

echarts力引导图关联关系图(适用于ie8)

适用于ie8的力引导图,是属于ets2.0的版本,在ie8上正常使用,简单易修改,需要传如两个数组即对象和数组
  图表
 17679  233

jQuery表头固定

基于superTables做的改造,可以完美锁定表头和列,已经用于实际项目,还有很多改造的空间
  图表
 40140  455

JS饼状图效果

基于highcharts.js实现的饼状图效果,报表
  图表
 48106  373

讨论这个项目(33)回答他人问题或分享插件使用方法奖励jQ币 评论用户自律公约

    常在 0
    2021/7/19 16:32:10
    怎么重复调用这个表格 比如点击按钮查询一个表就显示 大神出个办法 这个原代码是自调用方法 一次加载页面只能显示一次 回复
    Kitty.のバガ 0
    2020/6/18 22:06:16
    在哪里改默认排序规则啊?我用ID作首列,想倒序的,帮我强制正序排列了,在哪句代码里改 回复
    往后余生 0
    2019/11/5 11:31:11
    唯一的bug就是页面加载的时候 全部数据都出来了 回复
    往后余生 0
    2019/8/20 8:46:54
    刚和后端结合 很完美 唯一不好的地方 就是 那个模糊查询的搜索框 无法获取id或class并赋值 只能手动输入内容去搜索 回复
    妈妈叫我老八 0
    2018/8/17 16:23:35
    用ajax动态加表格的时候会出现No data available in table 这句话,然后操作以后,数据就不显示了,咋解决
        往后余生1
        2019/8/20 8:44:56
        那句话的意思就是 告诉你 table里没有可用的数据 当然不显示
    回复
    森七 0
    2018/6/20 15:57:47
    有bug啊,刷新页面的时候,全部的数据都出来了
        往后余生0
        2019/8/16 17:22:11
        js加载瞬间的 效果 你与后端结合一下 就不会这样了
    回复
    Keneath Chen 0
    2018/6/7 10:14:27
    影子独魂 0
    2018/6/4 22:20:08
    咋么才能获得JQ币
        .0
        2019/3/8 15:27:28
        个人中心>签到 (连续三天以上即可获得1JQ)
    回复
    施剑辉 0
    2018/4/23 18:39:43
     好人 0
    2018/1/10 14:23:19
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
取消回复