本文摘自PHP中文网,作者angryTom,侵删。
本篇文章为大家总结了几个使用bootstrap table实现分页时可能会遇到的问题,希望能够对大家有所帮助。
问题1 :服务器端取不到form值,querystring没有问题,但是request.form取不到值
解决:这是ajax的问题,原代码使用原生的ajax。 1可以用读流文件解决。2 如果想用request.form 方式,设置 contentType: "application/x-www-form-urlencoded",
1 2 3 4 5 6 7 8 9 10 | $( '#tableList' ).bootstrapTable({
method: 'post' ,
url: "" ,
height: $(window).height() - 200,
striped: true ,
dataType: "json" ,
pagination: true ,
"queryParamsType" : "limit" ,
singleSelect: false ,
contentType: "application/x-www-form-urlencoded" ,
|
问题2: 设置传递到服务器的参数
方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function queryParams(params) {
return {
pageSize: params.limit,
pageNumber: params.pageNumber,
UserName: 4
};
}
$( '#tableList' ).bootstrapTable({
method: 'post' ,
url: "" ,
height: $(window).height() - 200,
striped: true ,
dataType: "json" ,
pagination: true ,
queryParams: queryParams,
|
问题3: 后台取不到 pageSize 信息
解决:
1、在queryParams中设置
2、在bootstrap-table.minjs文件 修改源文件为"limit"===this.options.queryParamsType&&(e={limit:e.pageSize,pageNumber:e.pageNumber,
修改 bootstrap-table.js 也可以
1 2 3 4 5 6 7 8 9 10 11 12 13 | if ( this .options.queryParamsType === 'limit' ) {
params = {
search: params.searchText,
sort: params.sortName,
order: params.sortOrder
};
if ( this .options.pagination) {
params.limit = this .options.pageSize;
params.pageNumber= this .options.pageNumber,
params.offset = this .options.pageSize * ( this .options.pageNumber - 1);
}
}
|
3、配置加入 "queryParamsType": "limit",
完整:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | <script type= "text/javascript" >
$(document).ready( function () {
$( '#tableList' ).bootstrapTable({
method: 'post' ,
url: "getcompapylist" ,
height: $(window).height() - 200,
striped: true ,
dataType: "json" ,
pagination: true ,
"queryParamsType" : "limit" ,
singleSelect: false ,
contentType: "application/x-www-form-urlencoded" ,
pageSize: 10,
pageNumber:1,
search: false ,
showColumns: false ,
sidePagination: "server" ,
queryParams: queryParams,
responseHandler: responseHandler,
columns: [
{
field: 'CompanyId' ,
checkbox: true
}
{
field: 'qq' ,
title: 'qq' ,
width: 100,
align: 'center' ,
valign: 'middle' ,
sortable: false
}
,
{
field: 'companyName' ,
title: '姓名' ,
width: 100,
align: 'center' ,
valign: 'middle' ,
sortable: false
}
]
});
});
function responseHandler(res) {
if (res.IsOk) {
var result = b64.decode(res.ResultValue);
var resultStr = $.parseJSON(result);
return {
"rows" : resultStr.Items,
"total" : resultStr.TotalItems
};
} else {
return {
"rows" : [],
"total" : 0
};
}
}
function queryParams(params) {
return {
pageSize: params.limit,
pageNumber: params.pageNumber,
UserName: 4
};
}
</script>
|
问题4:分页后,重新搜索的问题
前提:自定义搜索且有分页功能,比如搜索产品名的功能.
现象:当搜索充气娃娃的时候返回100条记录,翻到第五页. 这时候搜索按摩棒,数据有200条,结果应该是第一页的记录,但是实际显示的还是第五页的结果. 也就是重新搜索后,pagenumber没有变.
解决:重新设置option就行了.
1 2 3 | function search(){
$( '#tableList' ).bootstrapTable({pageNumber:1,pageSize:10});
}
|
如果大家还想深入学习,可以点击这里进行学习,再为大家附3个精彩的专题:
Bootstrap视频教程
Bootstrap入门教程
以上就是Bootstrap table分页问题汇总【附答案&代码】的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
bootstrap怎么处理缓存问题
bootstrap的栅格系统是什么?栅格系统详解
bootstrap如何给div设置边框颜色
bootstrap table中toolbar新增条件查询及refresh参数使用方法
bootstrap是js框架吗
bootstrap layout it怎么使用
什么是bootstrap?它有什么作用
bootstrap如何拖拽组件
dialog是bootstrap的么
bootstrap基于什么开发
更多相关阅读请进入《bootstrap》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » Bootstrap table分页问题汇总【附答案&代码】