bootstrap-table分页插件使用

bootstrap-table介绍javascript

bootstrap-table 是一个轻量级的table插件,使用AJAX获取JSON格式的数据,其分页和数据填充很方便,支持国际化。css

下载地址java

https://github.com/wenzhixin/bootstrap-table/archive/1.11.0.zip

使用方式jquery

  1. 引入css和js
<!--css样式-->
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap/bootstrap-table.css" rel="stylesheet">
<!--js-->
<script src="js/bootstrap/jquery-1.12.0.min.js" type="text/javascript"></script>
<script src="js/bootstrap/bootstrap.min.js"></script>
<script src="js/bootstrap/bootstrap-table.js"></script>
<script src="js/bootstrap/bootstrap-table-zh-CN.js"></script>

    2. table数据填充git

    bootstrap-table获取数据有两种方式,一是经过table 的data-url属性指定数据源,二是经过JavaScript初始化表格时指定url来获取数据
 github

<table id="screenTable" data-toggle="table">
    <thead>
        ...
    </thead>
</table>
$(function () {
    $('#screenTable').bootstrapTable({
        url: "/screen/list",
        dataField: "rows",
        cache: false,               //是否使用缓存,默认为true
        striped: true,              //是否显示行间隔色
        pagination: true,           //是否显示分页
        pageSize: 10,               //每页的记录行数
        pageNumber: 1,              //初始化加载第一页,默认第一页
        pageList: [10, 20, 50],     //可供选择的每页的行数
        search: true,               //是否显示表格搜索
        showRefresh: true,          //是否显示刷新按钮
        clickToSelect: true,        //是否启用点击选中行
        toolbar: "#toolbar_screen", //工具按钮用哪一个容器
        sidePagination: "server",   //分页方式:client客户端分页,server服务端分页
        queryParamsType: "limit",   //查询参数组织方式

        columns: [{
            field: "id",
            title: "ID",
            align: "center",
            valign: "middle"
        }, {
            field: "name",
            title: "定制名称",
            align: "center",
            valign: "middle",
            formatter: 'infoFormatter'
        }, {
            field: "time",
            title: "定制时间",
            align: "center",
            valign: "middle"
        }],
        formatNoMatches: function () {
            return '无符合条件的记录';
        }
    });

    $(window).resize(function () {
        $('#screenTable').bootstrapTable('resetView');
    });
});
function infoFormatter(value, row, index) {
    return '<a href=/screen/' + row.id + ' target="_blank">' + row.name + '</a>';
}

效果图以下bootstrap

相关文章
相关标签/搜索