bootstroop table 自定义搜索
2016-12-07 14:16
302 查看
<div class="col-sm-12 ">
<div class="box">
<div class="box-header">
<h3 class="box-title">设备信息</h3>
</div>
<div id="toolbar">
1:<input id="s1" name="id" class="search">
2:<input id="s2" name="DeviceName" class="search">
<input type="button" onclick="searchkey();"
value="search">
</div>
<div class="box-body">
<table class="table table-bordered table-striped" id="mytab" ></table>
</div>
</div>
</div>
下面是js
<script>
function refresh(){//刷新
var nullparamss = {};
$("#mytab").bootstrapTable("refresh", nullparamss);
}
function autoRefresh(){//自动刷新
setTimeout(refresh,30000);
}
$('#mytab').bootstrapTable('resetSearch', {
height: tableHeight()
})
$(function () {
$("#refresh").click(function () {
refresh();
});
$(window).resize(function() { //根据窗口调整表格高度
$('#mytab').bootstrapTable('resetView', {
height: tableHeight()
})
})
$('#mytab').bootstrapTable({
url: "http://localhost/bootstrap/getJsonData?method=index2",//数据源
dataField: "rows",//服务端返回数据键值 就是说记录放的键值是rows,分页时使用总记录数的键值为total
totalField: 'total',
height: tableHeight(),//高度调整
sidePagination: "server",//服务端分页
method: "get",//请求方式
pagination: true,//是否分页
escape: true,
pageNumber: 1,
totalRows: 0, // server side need to set
queryParams: function getParams(params) {
var searchKey1 = $("#s1").val();
var searchKey2 = $("#s2").val();
var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的
limit: params.limit, //页面大小
searchKey1:searchKey1,
searchKey2:searchKey2,
sortName:this.sortName,
sortOrder:this.sortOrder,
pageindex:this.pageNumber//当前页码
};
return temp;
},
buttonsAlign: "left",//按钮对齐方式
selectItemName: 'id',
//uniqueId: "id", //每一行的唯一标识,一般为主键列
toolbar: "#toolbar",
toolbarAlign: 'left',
columns: [
{
title: "全选",//标题
width: 60,//宽度
align: "center",//水平
checkbox: true,
valign: "middle"//垂直
},
{
field: "id",
title: "id",
sortable: true
},
{
field: "DeviceName",
title: "DeviceName",
sortable: true
}
],
onRefresh: function (params) {
if($("#refreshWay .active").data("toggle")=== "off"){
autoRefresh();
}
},
locale: "zh-CN"//中文支持
});
});
function searchkey(){
var nullparamss = {};
$("#mytab").bootstrapTable("refresh", nullparamss);
}
function tableHeight() {
return $(window).height() - 219;
}
function infoFormatter(value, row, index)
{
return "<a href='detail.html'>id:" + row.id + " description:" + row.description + " done:" + row.done+"</a>";
}
</script>
<div class="box">
<div class="box-header">
<h3 class="box-title">设备信息</h3>
</div>
<div id="toolbar">
1:<input id="s1" name="id" class="search">
2:<input id="s2" name="DeviceName" class="search">
<input type="button" onclick="searchkey();"
value="search">
</div>
<div class="box-body">
<table class="table table-bordered table-striped" id="mytab" ></table>
</div>
</div>
</div>
下面是js
<script>
function refresh(){//刷新
var nullparamss = {};
$("#mytab").bootstrapTable("refresh", nullparamss);
}
function autoRefresh(){//自动刷新
setTimeout(refresh,30000);
}
$('#mytab').bootstrapTable('resetSearch', {
height: tableHeight()
})
$(function () {
$("#refresh").click(function () {
refresh();
});
$(window).resize(function() { //根据窗口调整表格高度
$('#mytab').bootstrapTable('resetView', {
height: tableHeight()
})
})
$('#mytab').bootstrapTable({
url: "http://localhost/bootstrap/getJsonData?method=index2",//数据源
dataField: "rows",//服务端返回数据键值 就是说记录放的键值是rows,分页时使用总记录数的键值为total
totalField: 'total',
height: tableHeight(),//高度调整
sidePagination: "server",//服务端分页
method: "get",//请求方式
pagination: true,//是否分页
escape: true,
pageNumber: 1,
totalRows: 0, // server side need to set
queryParams: function getParams(params) {
var searchKey1 = $("#s1").val();
var searchKey2 = $("#s2").val();
var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的
limit: params.limit, //页面大小
searchKey1:searchKey1,
searchKey2:searchKey2,
sortName:this.sortName,
sortOrder:this.sortOrder,
pageindex:this.pageNumber//当前页码
};
return temp;
},
buttonsAlign: "left",//按钮对齐方式
selectItemName: 'id',
//uniqueId: "id", //每一行的唯一标识,一般为主键列
toolbar: "#toolbar",
toolbarAlign: 'left',
columns: [
{
title: "全选",//标题
width: 60,//宽度
align: "center",//水平
checkbox: true,
valign: "middle"//垂直
},
{
field: "id",
title: "id",
sortable: true
},
{
field: "DeviceName",
title: "DeviceName",
sortable: true
}
],
onRefresh: function (params) {
if($("#refreshWay .active").data("toggle")=== "off"){
autoRefresh();
}
},
locale: "zh-CN"//中文支持
});
});
function searchkey(){
var nullparamss = {};
$("#mytab").bootstrapTable("refresh", nullparamss);
}
function tableHeight() {
return $(window).height() - 219;
}
function infoFormatter(value, row, index)
{
return "<a href='detail.html'>id:" + row.id + " description:" + row.description + " done:" + row.done+"</a>";
}
</script>
相关文章推荐
- bootstrap初试进度条
- Bootstrap 3.3.4 发布,Web 前端 UI 框架
- angular 指令简述
- BootStrap树状图显示功能
- 利用BootStrap弹出二级对话框的简单实现方法
- asp.net mvc4中bootstrap datetimepicker控件的使用
- NodeJS和BootStrap分页效果的实现代码
- 利用ASP.NET MVC+Bootstrap搭建个人博客之修复UEditor编辑时Bug(四)
- 浅析Bootstrap验证控件的使用
- 基于BootStrap Metronic开发框架经验小结【六】对话框及提示框的处理和优化
- bootstrap读书笔记之CSS组件(上)
- 使用BootStrap实现用户登录界面UI
- BootstrapValidator不触发校验的实现代码
- Bootstrap教程JS插件弹出框学习笔记分享
- Bootstrap插件全集
- BootStrap mvcpager分页样式(get请求,刷新页面)
- Bootstrap编写一个兼容主流浏览器的受众门户式风格页面
- Boostrap基础教程之JavaScript插件篇
- Bootstrap框架动态生成Web页面文章内目录的方法
- JS组件Bootstrap Table使用实例分享