jquery 的datatable 怎么用一个按钮代替它的搜索
1个回答
展开全部
//搜索按钮
<div class="container-fluid flu_bot">
<div class="col-md-1 col-sm-1"><button type="button" class="btn btn-primary" id="btnSearch">搜索</button></div>
</div>
//表格
<div class="container-fluid">
<table id="table-javascript"></table>
</div>
//初始化表格js
var TableInit = function () {
var oTableInit = new Object();
oTableInit.queryUrl = '/Official/GetSearchFileList' + '?rnd=' + +Math.random();
//初始化Table
oTableInit.Init = function () {
$('#table-javascript').bootstrapTable({
method: 'get',
url: oTableInit.queryUrl,
height: $(window).height() - 290,
striped: true,
pagination: true,
singleSelect: false,
pageSize: 15,
pageNumber: 1,
pageList: [10, 50, 100, 200, 500],
search: false, //不显示 搜索框
showColumns: false, //不显示下拉框(选择显示的列)
sidePagination: "server", //服务端请求
queryParams: oTableInit.queryParams,
minimunCountColumns: 2,
queryParamsType: "",//分页参数设置
formatNoMatches: function () {
return '未检索到信息';
},
columns: [
{
field: 'BH',
title: '序号',
width: 20,
align: 'center',
valign: 'middle',
sortable: false,
}, {
field: 'TITLE',
title: '名称',
width: 200,
align: 'left',
valign: 'top',
sortable: false,
}, {
field: 'Creater',
title: '创建人',
width: 50,
align: 'left',
valign: 'top',
sortable: false
}, {
field: 'CreateTime',
title: '创建时间',
width: 110,
align: 'middle',
valign: 'top',
sortable: false
}, {
field: 'operate',
title: '操作',
width: 100,
align: 'center',
valign: 'middle',
formatter: operateFormatter,
events: operateEvents
}],
onLoadSuccess: function () {
layer.msg('加载成功');
},
onLoadError: function () {
layer.msg('未检索到公文信息');
}
});
};
//销毁表格
oTableInit.Destory = function () {
$('#table-javascript').bootstrapTable('destroy');
};
//得到查询的参数
oTableInit.queryParams = function (params) {
var temp = {
pageSize: params.pageSize,
pageIndex: params.pageNumber,
Title:$("#Title").val(),
startDate: $("#startDate").val(),
endDate: $("#endDate").val()
};
return temp;
};
return oTableInit;
};
$(function () {
var oTable = new TableInit();
oTable.Init();
});
$("#btnSearch").click(function () {
var oTable = new TableInit();
oTable.Destory();
oTable.Init();
});
//后台接收参数
public ActionResult GetSearchFileList(string Title,DateTime? startDate,DateTime? endDate, int pageIndex = 1, int pageSize = 15)
<div class="container-fluid flu_bot">
<div class="col-md-1 col-sm-1"><button type="button" class="btn btn-primary" id="btnSearch">搜索</button></div>
</div>
//表格
<div class="container-fluid">
<table id="table-javascript"></table>
</div>
//初始化表格js
var TableInit = function () {
var oTableInit = new Object();
oTableInit.queryUrl = '/Official/GetSearchFileList' + '?rnd=' + +Math.random();
//初始化Table
oTableInit.Init = function () {
$('#table-javascript').bootstrapTable({
method: 'get',
url: oTableInit.queryUrl,
height: $(window).height() - 290,
striped: true,
pagination: true,
singleSelect: false,
pageSize: 15,
pageNumber: 1,
pageList: [10, 50, 100, 200, 500],
search: false, //不显示 搜索框
showColumns: false, //不显示下拉框(选择显示的列)
sidePagination: "server", //服务端请求
queryParams: oTableInit.queryParams,
minimunCountColumns: 2,
queryParamsType: "",//分页参数设置
formatNoMatches: function () {
return '未检索到信息';
},
columns: [
{
field: 'BH',
title: '序号',
width: 20,
align: 'center',
valign: 'middle',
sortable: false,
}, {
field: 'TITLE',
title: '名称',
width: 200,
align: 'left',
valign: 'top',
sortable: false,
}, {
field: 'Creater',
title: '创建人',
width: 50,
align: 'left',
valign: 'top',
sortable: false
}, {
field: 'CreateTime',
title: '创建时间',
width: 110,
align: 'middle',
valign: 'top',
sortable: false
}, {
field: 'operate',
title: '操作',
width: 100,
align: 'center',
valign: 'middle',
formatter: operateFormatter,
events: operateEvents
}],
onLoadSuccess: function () {
layer.msg('加载成功');
},
onLoadError: function () {
layer.msg('未检索到公文信息');
}
});
};
//销毁表格
oTableInit.Destory = function () {
$('#table-javascript').bootstrapTable('destroy');
};
//得到查询的参数
oTableInit.queryParams = function (params) {
var temp = {
pageSize: params.pageSize,
pageIndex: params.pageNumber,
Title:$("#Title").val(),
startDate: $("#startDate").val(),
endDate: $("#endDate").val()
};
return temp;
};
return oTableInit;
};
$(function () {
var oTable = new TableInit();
oTable.Init();
});
$("#btnSearch").click(function () {
var oTable = new TableInit();
oTable.Destory();
oTable.Init();
});
//后台接收参数
public ActionResult GetSearchFileList(string Title,DateTime? startDate,DateTime? endDate, int pageIndex = 1, int pageSize = 15)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询