bootstraptable使用实例

Samve      2022-02-14     584

关键词:

一、bootstrapTable简单使用:

<link rel="stylesheet" href="./static/libs/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="./static/libs/bootstrap-table-master/bootstrap-table.css">
<script src="./static/libs/jquery/jquery-1.11.2.min.js"></script>
<script src="./static/libs/bootstrap/js/bootstrap.js"></script>
<script src="./static/libs/bootstrap-table-master/bootstrap-table.js"></script>
<script src="./static/libs/bootstrap-table-master/locale/bootstrap-table-zh-CN.js"></script>

<div id="item_info_toolbar">
    <a href="javascript:void(0)" class="btn btn-default btn-sm" id="btnAddDept" style="text-decoration: none;" data-toggle="modal" data-target="#deptModal">创建</a>&nbsp;&nbsp;
    <a href="javascript:void(0)" class="btn btn-default btn-sm" id="btnAddDept" style="text-decoration: none;" data-toggle="modal" data-target="#adm-user-create-user">编辑</a>&nbsp;&nbsp;
    <a href="javascript:void(0)" class="btn btn-default btn-sm" id="btnAddDept" style="text-decoration: none;">删除</a>&nbsp;&nbsp;
    <a href="javascript:void(0)" class="btn btn-default btn-sm" id="btnEditDept" style="text-decoration: none;">排序</a>
    <a href="javascript:void(0)" class="btn btn-default btn-sm" id="btnEditDept" style="text-decoration: none;" onclick="getSelectValue()">获取选中行值</a>
</div>

<table id="table" data-toggle="table" class="table table-striped">
    <thead>
    <tr>

    </tr>
    </thead>
</table>
技术分享图片
<script>
$(‘#table‘).bootstrapTable(‘destroy‘).bootstrapTable({
        url: ‘data/‘ + ‘adm-user‘ + ‘.json‘,
        method: ‘POST‘,
        uniqueId: ‘id‘,                        // 绑定ID,不显示
        striped: false,                         //是否显示行间隔色
        cache: false,                          //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
        sortable: true,                        //是否启用排序
        sortOrder: "asc",                      //排序方式
        sidePagination: "client",              //分页方式:client客户端分页,server服务端分页(*)
        undefinedText: ‘--‘,
        //singleSelect: true,                  // 单选checkbox,默认为复选
        showRefresh   : true,                  // 显示刷新按钮
        showColumns   : true,                  // 选择显示的列
        toolbar: ‘#item_info_toolbar‘,         // 搜索框位置
        search: true,                          // 搜索开启,
        strictSearch: true,
        clickToSelect: true,                   // 点击选中行
        pagination: true,                      //是否显示分页
        pageNumber:1,                          //初始化加载第一页,默认第一页,并记录
        pageSize:5,//每页显示的数量
        pageList: [5, 10, 20, 50, 100],//设置每页显示的数量
        paginationPreText:"上一页",
        paginationNextText:"下一页",
        paginationLoop:false,
        //showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
        //cardView: false,                    //是否显示详细视图
        //detailView: false,                  //是否显示父子表
        //showPaginationSwitch: true,
        //得到查询的参数
        queryParams : function (params) {
            //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的
            var temp = {
                rows: params.limit,                         //页面大小
                page: (params.offset / params.limit) + 1,   //页码
                sort: params.sort,      //排序列名
                sortOrder: params.order //排位命令(desc,asc)
            };
            return temp;
        },
        columns: [
            {
             checkbox: true
            },{
            field: ‘username‘,
            title:‘用户名‘,
            valign: ‘middle‘,
            width: ‘16%‘,
            sortable: true
            },{
            field: ‘fullname‘,
            title:‘姓名‘,
            width: ‘16%‘
            },{
            field: ‘status‘,
            title:‘密码认证‘,
            width: ‘16%‘
            },{
            field: ‘availableSpace‘,
            title:‘智能卡认证‘,
            valign: ‘middle‘,
            width: ‘16%‘
            },{
            field: ‘totalSpace‘,
            title:‘个人空间配额‘,
            width: ‘16%‘
            },{
            field: ‘storageServer‘,
            title:‘私密空间配额‘,
            formatter: operateFormatter
            }
        ],
        onLoadSuccess: function () {
            alert(‘表格加载成功!‘);
        },
        onLoadError: function () {
            showTips("数据加载失败!");
        },
        onDblClickRow: function (row, $element) {
            var id = row.ID;
            //EditViewById(id, ‘view‘);
        },
        rowStyle: function (row, index) { //设置行的特殊样式
            //这里有5个取值颜色[‘active‘, ‘success‘, ‘info‘, ‘warning‘, ‘danger‘];
            var strclass = "";
            if (index == 1) {
                strclass = "warning";
                console.log(row);
            }
            return { classes: strclass }
        }
});

function getSelectValue(){
    var a = $table.bootstrapTable(‘getSelections‘);//获取选中行的数据
    if(a.length > 0){
        console.log(a);
    }
}

function operateFormatter (value, row, index) {
    var result = ‘<button class="btn  btn-action" title="激活USBKEY认证" onclick=""><i class="glyphicon glyphicon-pencil"></i></button>‘
    return result;
}
</script>
技术分享图片

adm-user: 

    [
        {
        	"id": 2018100701,
            "username": "user1",
            "fullname": "用户1",
            "status": "启用",
            "availableSpace": "10GB",
            "totalSpace": "20GB",
            "storageServer" : "nas1"
        },
        {
        	"id": 2018100702,
            "username": "user2",
            "fullname": "用户2",
            "status": "启用",
            "availableSpace": "10GB",
            "totalSpace": "20GB",
            "storageServer" : "nas1"
        },
        {
        	"id": 2018100703,
            "username": "user3",
            "fullname": "用户3",
            "status": "启用",
            "availableSpace": "10GB",
            "totalSpace": "20GB",
            "storageServer" : "nas1"
        },
        {
        	"id": 2018100704,
            "username": "user4",
            "fullname": "用户4",
            "status": "启用",
            "availableSpace": "10GB",
            "totalSpace": "20GB",
            "storageServer" : "nas1"
        },
        {
       	    "id": 2018100705,
            "username": "user5",
            "fullname": "用户5",
            "status": "启用",
            "availableSpace": "10GB",
            "totalSpace": "20GB",
            "storageServer" : "nas1"
        },
        {
            "id": 2018100706,
            "username": "user6",
            "fullname": "用户6",
            "status": "启用",
            "availableSpace": "10GB",
            "totalSpace": "20GB",
            "storageServer" : "nas1"
        },
        {
            "id": 2018100707,
            "username": "user7",
            "fullname": "用户7",
            "status": "启用",
            "availableSpace": "10GB",
            "totalSpace": "20GB",
            "storageServer" : "nas1"
        },
        {
            "id": 2018100708,
            "username": "user8",
            "fullname": "用户8",
            "status": "启用",
            "availableSpace": "10GB",
            "totalSpace": "20GB",
            "storageServer" : "nas1"
        },
        {
            "id": 2018100709,
            "username": "user9",
            "fullname": "用户9",
            "status": "启用",
            "availableSpace": "10GB",
            "totalSpace": "20GB",
            "storageServer" : "nas1"
        },
        {
            "id": 2018100710,
            "username": "user10",
            "fullname": "用户10",
            "status": "启用",
            "availableSpace": "10GB",
            "totalSpace": "20GB",
            "storageServer" : "nas1"
        },
        {
            "id": 2018100711,
            "username": "user11",
            "fullname": "用户11",
            "status": "启用",
            "availableSpace": "10GB",
            "totalSpace": "20GB",
            "storageServer" : "nas1"
        }
    ]
技术分享图片

 二、 利用bootstrapTable来设置要隐藏和显示的列:

$(function () {
//初始化table
  LoadingDataListOrderRealItems();
//隐藏列
  $(‘#tableOrderRealItems‘).bootstrapTable(‘showColumn‘, ‘ShopName‘);
  $(‘#tableOrderRealItems‘).bootstrapTable(‘hideColumn‘, ‘GoodsId‘);
  $(‘#tableOrderRealItems‘).bootstrapTable(‘hideColumn‘, ‘OrderItemId‘);
  $(‘#tableOrderRealItems‘).bootstrapTable(‘hideColumn‘, ‘ShopName‘);      
  $(‘#tableOrderRealItems‘).bootstrapTable(‘hideColumn‘, ‘SellerName‘);
}); 
技术分享图片

三、 也可以直接使用hidden属性来设置:

columns: [
    {
          field: ‘OrderId‘,
          title: ‘#‘,
          align: ‘center‘,
     }, {
          field: ‘OrderItemId‘,
          title: ‘OrderItemId‘,
          align: ‘left‘,
          hidden:true,
     }, {
          field: ‘GoodsId‘,
          title: ‘GoodsId‘,
          align: ‘left‘,
          hidden:true,
     }, {
          field: ‘OrderCode‘,
          title: ‘订单编号‘,
          align: ‘left‘,
    }
]
技术分享图片

四、如何获取数据:

方式一:表格中配置

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.min.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.css">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.1.1/js/bootstrap.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.js"></script>
<!-- Latest compiled and minified Locales -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/locale/bootstrap-table-zh-CN.min.js"></script>
</head>
<body>
<table id="table"
       data-toggle="table"
       data-url="data/table.json"
       data-pagination="true"
       data-page-number=1
       data-page-size=10
       data-search=true
       data-show-refresh=true
       data-show-pagination-switch=true
       data-search-align="left"
>
<thead>
<tr>
    <th data-field="id">id</th>
    <th data-field="name">name</th>
    <th data-field="price">price</th>
    <th data-field="column1">column1</th>
    <th data-field="column2">column2</th>
    <th data-field="column3">column3</th>
    <th data-field="column4">column4</th>
</tr>
</thead>
</table>

<script>
$(function () {
    //隐藏列
    $(‘#table‘).bootstrapTable(‘hideColumn‘, ‘column4‘);
})
</script>
</body>
</html>
技术分享图片

 方式二:JavaScript配置

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.min.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.css">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.1.1/js/bootstrap.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.js"></script>
<!-- Latest compiled and minified Locales -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/locale/bootstrap-table-zh-CN.min.js"></script>
</head>
<body>
<button onclick="getData(‘table2‘)">点击获取数据</button>
<table id="table" data-toggle="table">
<thead>
<tr>
    <th data-field="id">id</th>
    <th data-field="name">name</th>
    <th data-field="price">price</th>
    <th data-field="column1">column1</th>
    <th data-field="column2">column2</th>
    <th data-field="column3">column3</th>
    <th data-field="column4">column4</th>
</tr>
</thead>
</table>

<script>
function getData(url){
    $(‘#table‘).bootstrapTable(‘destroy‘).bootstrapTable({  //‘destroy‘ 是必须要加的==作用是加载服务器//  //数据,初始化表格的内容Destroy the bootstrap table.
        url: ‘data/‘ + url + ‘.json‘,
        pagination: true,
        pageList:[],
        pageNumber:1,
        pageSize:5,//每页显示的数量
        paginationPreText:"上一页",
        paginationNextText:"下一页",
        paginationLoop:false,
        columns: [
             {
                field: ‘id‘,
                title:‘id‘,
                valign: ‘middle‘,
            },{
                field: ‘name‘,
                title:‘name‘
            },{
                field: ‘price‘,
                title:‘price‘
            },{
                field: ‘column1‘,
                title:‘请求内容‘
            },{
                field: ‘column2‘,
                title:‘请求内容‘
            },{
                field: ‘column3‘,
                title:‘请求内容‘
            },{
                field: ‘column4‘,
                title:‘请求内容‘
            }
        ]
    })
}
</script>
</body>
</html>
技术分享图片
[
    {
        "id": 0,
        "name": "Item 0",
        "price": "$0",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 1,
        "name": "Item 1",
        "price": "$1",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 2,
        "name": "Item 2",
        "price": "$2",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 3,
        "name": "Item 3",
        "price": "$3",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 4,
        "name": "Item 4",
        "price": "$4",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 5,
        "name": "Item 5",
        "price": "$5",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 6,
        "name": "Item 6",
        "price": "$6",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 7,
        "name": "Item 7",
        "price": "$7",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 8,
        "name": "Item 8",
        "price": "$8",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 9,
        "name": "Item 9",
        "price": "$9",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 10,
        "name": "Item 10",
        "price": "$10",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 11,
        "name": "Item 11",
        "price": "$11",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 12,
        "name": "Item 12",
        "price": "$12",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 13,
        "name": "Item 13",
        "price": "$13",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 14,
        "name": "Item 14",
        "price": "$14",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 15,
        "name": "Item 15",
        "price": "$15",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 16,
        "name": "Item 16",
        "price": "$16",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 17,
        "name": "Item 17",
        "price": "$17",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 18,
        "name": "Item 18",
        "price": "$18",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 19,
        "name": "Item 19",
        "price": "$19",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    },
    {
        "id": 20,
        "name": "Item 20",
        "price": "$20",
        "column1": "C 10",
        "column2": "C 20",
        "column3": "C 30",
        "column4": "C 40"
    }
]
技术分享图片

五、BootstrapTable前后端完整实例(以ASP.NET为例):

以一个基于BootstrapTable控件的图书列表查询功能为实例(如图1)。注意本实例使用了ASP.NET MVC。

技术分享图片技术分享图片?

页面代码:

@{
Layout = null;
ViewBag.Title = "基于BootstrapTable的简单应用";
}
<!--添加相关样式引用-->
<link href="~/Content/bootstrap.min.css" rel="stylesheet"/>
<link href="~/Content/bootstrap-table.min.css" rel="stylesheet"/>
<div class="container body-content" style="padding-top:20px;">
    <div class="panel panel-default">
        <div class="panel-heading">
            查询条件
        </div>
        <div class="panel-body">
            <form class="form-inline">
                <div class="row">
                    <div class="col-sm-4">
                        <label class="control-label">图书名称:</label><input id="txtTitle" type="text" class="form-control">
                    </div>
                    <div class="col-sm-4">
                        <label class="control-label">图书作者:</label><input id="txtAuthor" type="text" class="form-control">
                    </div>
                    <div class="col-sm-4">
                        <label class="control-label">出版社:</label><input id="txtPublish" type="text" class="form-control">
                    </div>
                </div>
                <div class="row text-right" style="margin-top:20px;">
                    <div class="col-sm-12">
                        <input class="btn btn-primary" type="button" value="查询" onclick="SearchData()"><input class="btn btn-default" type="button" value="批量删除" onclick="BtchDeleteBook()">
                    </div>
                </div>
            </form>
        </div>
    </div>
    <table id="table">
    </table>
</div>
<!--添加相关脚本引用-->
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/bootstrap-table.min.js"></script>
<script src="~/Scripts/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
    $(‘#table‘).bootstrapTable({
        url: ‘@Url.Action("SearchBookInfo", "Home")‘,
        queryParamsType: ‘‘,              //默认值为 ‘limit‘ ,在默认情况下 传给服务端的参数为:offset,limit,sort//
        queryParams: queryParams,
        method: "post",
        pagination: true,
        pageNumber: 1,
        pageSize: 2,
        pageList: [10, 20, 50, 100],
        sidePagination: "server",         //分页方式:client客户端分页,server服务端分页(*)
        striped: true,                    //是否显示行间隔色
        cache: false,
        uniqueId: "BookId",               //每一行的唯一标识,一般为主键列
        height:300,
        paginationPreText: "上一页",
        paginationNextText: "下一页",
        columns: [
            { checkbox: true },
            { title: ‘序号‘, width: 50, align: "center", formatter: function (value, row, index) { return index + 1; } },
            { title: ‘图书名称‘, field: ‘Title‘ },
            { title: ‘图书作者‘, field: ‘Author‘ },
            { title: ‘销售价格‘, field: ‘Price‘ },
            { title: ‘出版社‘, field: ‘Publish‘ },
            { title: ‘出版时间‘, field: ‘PublishDate‘, formatter: function (value, row, index) {
                     if (value == null)
                         return "";
                     else {
                         var pa = /.*((.*))/;
                         var unixtime = value.match(pa)[1].substring(0, 10);
                         return getShortTime(unixtime);
                     }
                 }
            },
            { title: ‘操作‘, field: ‘BookId‘, formatter: function (value, row, index) {
                 var html = ‘<a href="javascript:EditBook(‘+ value + ‘)">编辑</a>‘;
                 html += ‘ <a href="javascript:DeleteBook(‘ + value + ‘)">删除</a>‘;
                 return html;
                }
        }]
    });
});

//查询条件
function queryParams(params) {
    return {
        pageSize: params.pageSize,
        pageIndex: params.pageNumber,
        Title: $.trim($("#txtTitle").val()),
        Author: $.trim($("#txtAuthor").val()),
        Publish: $.trim($("#txtPublish").val()),
    };
}

//查询事件
function SearchData() {
    $(‘#table‘).bootstrapTable(‘refresh‘, { pageNumber: 1 });
}

//编辑操作
function EditBook(bookId){
    alert("编辑操作,图书ID:" + bookId);
}

//删除操作
function DeleteBook(bookId) {
    if (confirm("确定删除图书ID:" + bookId + "吗?"))        {
        alert("执行删除操作");
    }
}

//批量删除
function BtchDeleteBook(){
    var opts = $(‘#table‘).bootstrapTable(‘getSelections‘);
    if (opts == "") {
        alert("请选择要删除的数据");
    } else {
        var idArray = [];
        for (var i = 0; i < opts.length; i++) {
            idArray.push(opts[i].BookId);
        }
        if (confirm("确定删除图书ID:" + idArray + "吗?")) {
            alert("执行删除操作");
        }
    }
}

function getTime(/** timestamp=0 **/) {
    var ts = arguments[0] || 0;
    var t, y, m, d, h, i, s;
    t = ts ? new Date(ts * 1000) : new Date();
    y = t.getFullYear();
    m = t.getMonth() + 1;
    d = t.getDate();
    h = t.getHours();
    i = t.getMinutes();
    s = t.getSeconds();        
    // 可根据需要在这里定义时间格式
    return y + ‘-‘ + (m < 10 ? ‘0‘ + m : m) + ‘-‘ + (d < 10 ? ‘0‘ + d : d) + ‘ ‘ + (h < 10 ? ‘0‘ + h : h) + ‘:‘ + (i < 10 ? ‘0‘ + i : i) + ‘:‘ + (s < 10 ? ‘0‘ + s : s);
}
function getShortTime(/** timestamp=0 **/) {
    var ts = arguments[0] || 0;
    var t, y, m, d, h, i, s;
    t = ts ? new Date(ts * 1000) : new Date();
    y = t.getFullYear();
    m = t.getMonth() + 1;
    d = t.getDate();        
    // 可根据需要在这里定义时间格式
    return y + ‘-‘ + (m < 10 ? ‘0‘ + m : m) + ‘-‘ + (d < 10 ? ‘0‘ + d : d);
}
</script>
技术分享图片

控制器代码:

/// <summary>
/// 查询图书信息
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
public JsonResult SearchBookInfo(BookInfo param, int pageSize, int pageIndex){
    //获取图书列表
    List<BookInfo> bookList = GetBookList();
    //根据条件筛选数据
    if (!String.IsNullOrEmpty(param.Title))    {
        bookList = bookList.Where(a => a.Title.Contains(param.Title)).ToList();
    }
    if (!String.IsNullOrEmpty(param.Author))    {
        bookList = bookList.Where(a => a.Author.Contains(param.Author)).ToList();
    }
    if (!String.IsNullOrEmpty(param.Publish))    {
        bookList = bookList.Where(a => a.Publish.Contains(param.Publish)).ToList();
    }
    //BootstrapTable的返回结果
    BootstrapTableResult<BookInfo> result = new BootstrapTableResult<BookInfo>();
    result.total = bookList.Count;
    result.rows = bookList;
    return Json(result);
}

/// <summary>
/// 获取图书列表
/// </summary>
/// <returns></returns>
public List<BookInfo> GetBookList(){
    List<BookInfo> bookList = new List<BookInfo>();
    BookInfo book1 = new BookInfo(){
        BookId = 8,
        Title = "ASP.NET MVC 5高级编程",
        Author = "加洛韦",
        Publish = "清华大学出版社",
        PublishDate = new DateTime(2017, 08, 15),
        Price = 29.99
    };
    bookList.Add(book1);
    BookInfo book2 = new BookInfo() {
        BookId = 9,
        Title = "Java从入门到精通",
        Author = "明日科技",
        Publish = "清华大学出版社",
        PublishDate = new DateTime(2015, 09, 28),
        Price = 38.55
    };
    bookList.Add(book2);
    BookInfo book3 = new BookInfo() {
        BookId = 10,
        Title = "Oracle从入门到精通",
        Author = "秦靖",
        Publish = "机械工业出版社",
        PublishDate = new DateTime(2014, 10, 08),
        Price = 38.55
    };
    bookList.Add(book3);
    return bookList;
}
技术分享图片

其他代码:

/// <summary>
/// 图书信息实体类
/// </summary>
public class BookInfo{
    public int BookId { set; get; }             //图书ID
    public string Title { set; get; }           //图书名称
    public string Author { set; get; }          //图书作者
    public string Publish { set; get; }         //出版社
    public DateTime PublishDate { set; get; }   //出版时间
    public Double Price { set; get; }           //销售价格
}
技术分享图片
/// <summary>
/// BootstrapTable返回结果类
/// </summary>
public class BootstrapTableResult<T>{
    public int total { get; set; }      //总记录数
    public List<T> rows { get; set;}   //数据列表
}
技术分享图片

六、Bootstrap table中toolbar新增条件查询及refresh参数使用方法:

我们想要在bootstrap-table中自定义查询条件如何实现呢?这些自定义的按钮、输入框是定义在哪个位置呢?在配置中有这样一个属性:

//工具按钮用哪个容器
toolbar: ‘#toolbar‘,
<div id="toolbar"></div>
技术分享图片

我们定义的查询条件就是放入到这个div中的,先看一下我们期望的效果:

技术分享图片技术分享图片?

要实现这样的效果,我们首先要新增查询表单:

<div class="container">
 <div class="row">
  <div class="table-responsive">
   <div id="toolbar">
    <form class="form-inline">
     <div class="form-group">
     <label class="sr-only" for="product_line">产品线</label>
     <div class="input-group">
      <div class="input-group-addon">产品线</div>
      <select class="form-control" name="product_line" id="productLine">
       <option value="">请选择产品线...</option>
      </select>
     </div>
     </div>
     <div class="form-group">
     <label class="sr-only" for="msg_type">消息类型</label>
     <div class="input-group">
      <div class="input-group-addon">消息类型</div>
      <select class="form-control" name="msg_type" id="msgType">
       <option value="">请选择消息类型...</option>
      </select>
     </div>
     </div>
     <div class="form-group">
     <label class="sr-only" for="msg_type">消息类型</label>
     <div class="input-group">
      <div class="input-group-addon">消息类型</div>
      <input type="text" class="form-control" name="searchTexts" id="searchText" placeholder="请输入消息名称或内容关键字...">
     </div>
     </div>
     <button type="button" class="btn btn-primary queryButton">查询</button>
    </form>
   </div>
   <table id="table" ></table>
  </div>
 </div>
</div>
技术分享图片

 在请求服务器中传递的参数中获取对应的值:

//请求服务器数据
 queryParams: function queryParams(params){
  var param = {
    pageNumber: params.pageNumber,
    pageSize: params.pageSize,
    sortName: params.sortName,
    sortOrder: params.sortOrder,
    searchText: $("#searchText").val(),
    msgType: $("#msgType").val(),
    productLine: $("#productLine").val()
   };
   return param;
 }
技术分享图片

最后是提交到服务端:

//查询
$(document).on(‘click‘, ".queryButton",function(){
  $(‘#table‘).bootstrapTable(‘refresh‘);
});
技术分享图片

这个refresh官方文档是这样描述的:

刷新远程服务器数据,可以设置{silent: true}以静默方式刷新数据,并设置{url: newUrl}更改URL。 
要提供特定于此请求的查询参数,请设置{query: {foo: ‘bar‘}}。


161221bootstraptable实例

bootstraptable封装了一套完善的数据表格组件,把下面的代码复制一下估计你需要的基本功能都有了,没有的再看看手册对比着我给的实例也能很快的熟悉了客户端<!DOCTYPE html><html><head>    <meta ... 查看详情

bootstraptable源码

....pluginName外围,通过实例化$ele.data(‘bootstrap.table‘,(dat=newBootstrapTable(thi 查看详情

bootstraptable如何使用

最近在使用bootStrapTable的表格功能有一些自己的理解写下来分享一下主要用的是一个bootStrapTable和jquery的混合开发具体怎样引入bootStrapTable我就不一一详解了直接上代码htm代码<tableid="table0"></table>js代码var$table=$(‘#table0‘)... 查看详情

bootstraptable使用小记

varTableInit=function(){varoTableInit=newObject();//初始化TableoTableInit.Init=function(){$(‘#tb_rolelist‘).bootstrapTable({url:‘/Role/GetList‘,//请求后台的URL(*)method:‘get‘,//请求方式(*)toolbar:‘#toolbar‘,//工具按 查看详情

bootstraptable使用总结

使用bootstraptable可以很方便的开发后台表格,对数据进行异步更新,编辑。下面就来介绍一下bootstraptable的详细使用方法:因为之前在官网也找了很久的教程,源码感觉隐藏的比较隐秘,其他扩展功能也很难找到,其实都在:http:... 查看详情

bootstraptable的使用

前言:BootstrapTable基于Bootstrap,Bootstrap基于jquery,所以需要引入jquery后再引入bootstrap。<linkhref="${ctx}/assets/plugins/bootstrap/css/bootstrap.min.css"rel="stylesheet"><linkrel="stylesheet"href="${ctx}/as 查看详情

bootstraptable使用心得

 序号显示带分页信息的连续编号,在序号列添加以下格式化代码即可。{field:‘number‘,title:‘序号‘,align:‘center‘,width:45,formatter:function(value,row,index){varpageSize=$(‘#logList‘).bootstrapTable(‘getOptions‘).pageSize,pageNum=$(‘#logLi 查看详情

bootstraptable的使用小结

...一下,毕竟有些时候没有使用到这个方式很有用,在使用bootstraptable的时候,选择当前已经选择的节点的事件中的ID的值 当前rows中有很多的数据,但是我只需要id这一个值,这个时候进行操作就非常的简单了。$.map(data,function(... 查看详情

bootstraptable的使用小结

...一下,毕竟有些时候没有使用到这个方式很有用,在使用bootstraptable的时候,选择当前已经选择的节点的事件中的ID的值 当前rows中有很多的数据,但是我只需要id这一个值,这个时候进行操作就非常的简单了。$.map(data,function(... 查看详情

bootstraptable使用

bootstraptablegitaddresshttps://github.com/wenzhixin/bootstrap-table 引入文件<linkrel="stylesheet"href="../bower_components/bootstrap/dist/css/bootstrap.min.css"/><linkrel="stylesheet"href=" 查看详情

bootstraptable学习笔记

资料:官网  2017.7.10入门实例<!DOCTYPEhtml><html><head><metacharset="utf-8"/><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=dev 查看详情

使用 BootstrapTable 添加行时使用 CellStyle

】使用BootstrapTable添加行时使用CellStyle【英文标题】:UsingCellStylewhenaddingrowswithBootstrapTable【发布时间】:2018-06-2005:19:54【问题描述】:我有一个带有按钮的引导表,用于添加新的数据行。我想在插入时为每个新行的某一列(text2... 查看详情

bootstraptable错误

异常:Cannotreadproperty‘field‘ofundefined场景:使用BootStrapTable展示数据时,控制台报错解决:给table加上thead和tbody标签 异常:使用tablednd插件时,onDrap方法不调用解决:给tr标签加id属性 查看详情

bootstraptable使用及遇到的问题

本人前端菜鸟一枚,最近使用bootstraptable实现表格,记录一下以便日后翻阅,废话不多说,先看效果图:1、首先说下要实现该效果需要添加的css样式及所需的js文件,具体下载地址就不粘贴了(因为太懒)<linkrel="stylesheet"href="css/b... 查看详情

bootstraptable使用示例及代码

http://issues.wenzhixin.net.cn/bootstrap-table/ <!DOCTYPEhtml><html><head><title>BootstrapTableExamples</title><linkrel="stylesheet"href="assets/bootstrap/css/boo 查看详情

如何让bootstraptable语言包使用

参考技术A设置如下样式是可以使表格内容居中的,没有居中的原因可能是你还设置了其他的样式(把这个样式覆盖了):.tableth,.tabletdtext-align:center;height:38px;你可以新建一个单独的html文件复制如下代码来测试一下:BootstrapTable 查看详情

bootstraptable的一些简单使用总结

在GitHub上Bootstrap-table的源码地址是:https://github.com/wenzhixin/bootstrap-tableBootstrap-table的文档地址:http://bootstrap-table.wenzhixin.net.cn/Bootstrap-table的各种样例:https://github.com/wenzhixin/bootstrap-table 查看详情

bootstraptable使用心得总结

...的表格控件,查询到:http://bootstrap-table.wenzhixin.net.cn的BootstrapTable感觉挺不错,但是由于官方的文档不是怎么的完善,导致自己的网络数据请求一直没有通过。今天终于调试通过,在这里与大家分享一下。一、相关... 查看详情