BootStrap Table - 踩坑

1.使用bootstraptable V4 版的Api,使用的jquery版本必须是 jquery-1.10.2.min.js 及以上的

否则,会有引发意想不到的bug

bug1:后台传到前台的数据都是好的,格式也正确,但是表格的tbody标签里面就是不添加行,浏览器无任何报错。

2.老版本(bootstraptable V3 版)的Api绑定数据,需要带上  data-response-handler="responseHandler" 属性,否则不显示数据

新版(bootstraptable V4 版,bootstrap-table@1.18.3 )及之后的版本不需要此属性。

3.Mvc中以PartialView+前台数据加载的方式(data-toggle="table")加载数据,汉化属性(data-locale="zh-CN")不生效,故需要使用JS加载的方式

<table
    id="table"
    data-locale="zh-CN"
    data-height="660"
    data-pagination="true"
    data-search="true"
    data-search-align="left"
    data-search-highlight="true"
    data-search-on-enter-key="true"
    data-response-handler="responseHandler"
    data-url="/Business/ProduceManage/Biz_Sell_Produceshipping/LoadWeiKaiPanTask">
    <thead>
        <tr>
            <th data-field="操作" data-formatter="cmmdFormatWeiKaiPan">操作</th>
            <th data-field="任务编号">任务编号</th>
            <th data-field="单位名称">单位名称</th>
            <th data-field="工程名称">工程名称</th>
            <th data-field="施工部位">施工部位</th>
            <th data-field="任务方量">任务方量</th>
            <th data-field="浇筑方式">浇筑方式</th>
            <th data-field="标号全称">标号全称</th>
            <th data-field="要求发货时间">要求发货时间</th>
            <th data-field="ID" data-visible="false">ID</th>
        </tr>
    </thead>
</table>
View Code
$.extend($.fn.bootstrapTable.defaults, {
     data_locale: 'zh-CN'
});
$('#table').bootstrapTable();
View Code

4.JS方式加载数据如果是服务端方式加载(sidePagination: "server")则请求的Url返回格式为data = {isSuccess: true, rows: Array(100)},rows属性为数据源

如果是默认方式加载则请求的Url返回格式为数组对象数据源,此时需要增加responseHandler: responseHandler,来重定义数据源,这里的res即为返回的data

function responseHandler(res) {
    return res.rows;
}

5.

 

posted @ 2021-03-14 15:36  竹殇  阅读(412)  评论(0)    收藏  举报