Bootstrap Table使用整理(五)-分页组合查询
2017-08-16 11:16
417 查看
一、分页组合查询
[javascript] view
plain copy
print?
/*
* data-pagination 指定是否启用分页
* data-page-list 指定分页的页数据量数组 '[5,10]'
* data-side-pagination 指定分页是否是服务端(server)/客户端(client)
* 特别说明:
* 客户端,请求参数:
* search:文本框内容,在文本框内容改变是自动提交请求
* order: 排序方式
* sort:排序列名
* offset:划过条数
* limit:要获取的数据的条数
*
*/
var $table1= $('#table1').bootstrapTable({
columns: [
{ field: 'sno', title: '学生编号',sortable:true },
{ field: 'sname', title: '学生姓名' },
{ field: 'ssex', title: '性别' },
{ field: 'sbirthday', title: '生日' },
{ field: 'class', title: '课程编号' },
],
url: '@Url.Action("GetStuList", "DataOne")',
pagination: true,
sidePagination: 'server',
pageList:[5,10,20,50],
queryParams: function (params) {
params.name = '张三丰';
//特别说明,返回的参数的值为空,则当前参数不会发送到服务器端
//这种指定请求参数的方式和datatables控价类似
params.sex = $('input[name="sex"]:checked').val();
return params;
}
});
//刷新方法
$('#heartBtn').click(function () {
$table1.bootstrapTable('refresh');
});
[html] view
plain copy
print?
<table id="table1"
data-classes="table table-hover "
data-search="true"
data-show-refresh="true"
data-show-toggle="true"
data-show-columns="true"
data-toolbar="#toolbar"></table>
<div id="toolbar">
<div class="btn-group">
<button class="btn btn-default">
<i class="glyphicon glyphicon-plus"></i>
</button>
<button class="btn btn-default">
<i class="glyphicon glyphicon-heart" id="heartBtn"></i>
</button>
<button class="btn btn-default">
<i class="glyphicon glyphicon-trash"></i>
</button>
</div>
<div class="form-group">
<label class="control-label">性别:</label>
<label class="radio-inline">
<input type="radio" name="sex" value="男" /> 男
</label>
<label class="radio-inline">
<input type="radio" name="sex" value="女" /> 女
</label>
</div>
</div>
2.服务端代码处理
[csharp] view
plain copy
print?
public JsonResult GetStuList(string sex, string search, string sort, string order, int offset, int limit)
{
var query = _Context.Student.AsQueryable();
if (string.IsNullOrEmpty(sex) == false)
query = query.Where(q => q.Ssex == sex);
if (string.IsNullOrEmpty(search) == false)
query = query.Where(q => q.Sno.Contains(search) || q.Sname.Contains(search));
//排序
if (sort == "sno")
{
if (order == "asc")
query = query.OrderBy(q => q.Sno);
else
query = query.OrderByDescending(q => q.Sno);
}
else
query = query.OrderBy(q => q.Sbirthday);
int total = query.Count();
var list = query.Skip(offset).Take(limit).ToList();
return Json(new
{
rows = list,
total = total
});
}
[javascript] view
plain copy
print?
/*
* data-pagination 指定是否启用分页
* data-page-list 指定分页的页数据量数组 '[5,10]'
* data-side-pagination 指定分页是否是服务端(server)/客户端(client)
* 特别说明:
* 客户端,请求参数:
* search:文本框内容,在文本框内容改变是自动提交请求
* order: 排序方式
* sort:排序列名
* offset:划过条数
* limit:要获取的数据的条数
*
*/
var $table1= $('#table1').bootstrapTable({
columns: [
{ field: 'sno', title: '学生编号',sortable:true },
{ field: 'sname', title: '学生姓名' },
{ field: 'ssex', title: '性别' },
{ field: 'sbirthday', title: '生日' },
{ field: 'class', title: '课程编号' },
],
url: '@Url.Action("GetStuList", "DataOne")',
pagination: true,
sidePagination: 'server',
pageList:[5,10,20,50],
queryParams: function (params) {
params.name = '张三丰';
//特别说明,返回的参数的值为空,则当前参数不会发送到服务器端
//这种指定请求参数的方式和datatables控价类似
params.sex = $('input[name="sex"]:checked').val();
return params;
}
});
//刷新方法
$('#heartBtn').click(function () {
$table1.bootstrapTable('refresh');
});
[html] view
plain copy
print?
<table id="table1"
data-classes="table table-hover "
data-search="true"
data-show-refresh="true"
data-show-toggle="true"
data-show-columns="true"
data-toolbar="#toolbar"></table>
<div id="toolbar">
<div class="btn-group">
<button class="btn btn-default">
<i class="glyphicon glyphicon-plus"></i>
</button>
<button class="btn btn-default">
<i class="glyphicon glyphicon-heart" id="heartBtn"></i>
</button>
<button class="btn btn-default">
<i class="glyphicon glyphicon-trash"></i>
</button>
</div>
<div class="form-group">
<label class="control-label">性别:</label>
<label class="radio-inline">
<input type="radio" name="sex" value="男" /> 男
</label>
<label class="radio-inline">
<input type="radio" name="sex" value="女" /> 女
</label>
</div>
</div>
2.服务端代码处理
[csharp] view
plain copy
print?
public JsonResult GetStuList(string sex, string search, string sort, string order, int offset, int limit)
{
var query = _Context.Student.AsQueryable();
if (string.IsNullOrEmpty(sex) == false)
query = query.Where(q => q.Ssex == sex);
if (string.IsNullOrEmpty(search) == false)
query = query.Where(q => q.Sno.Contains(search) || q.Sname.Contains(search));
//排序
if (sort == "sno")
{
if (order == "asc")
query = query.OrderBy(q => q.Sno);
else
query = query.OrderByDescending(q => q.Sno);
}
else
query = query.OrderBy(q => q.Sbirthday);
int total = query.Count();
var list = query.Skip(offset).Take(limit).ToList();
return Json(new
{
rows = list,
total = total
});
}
相关文章推荐
- Bootstrap Table使用整理(五)-分页组合查询
- Bootstrap Table使用整理(五)之分页组合查询
- MVC无刷新查询,PagedList分页控件使用,导出Excel
- MyBatis使用(二)分页查询
- SQL Server2005使用ROW_NUMBER() OVER实现按分组查询Count()数量排序并分页
- 使用SQL语句对表进行分页查询
- myBatis学习笔记(10)——使用拦截器实现分页查询
- Elasticsearch使用scroll进行分页查询
- JDBC实现分页查询,同时使用动态数据源
- mysql大数据量使用limit分页,随着页码的增大,查询效率底下的解决办法
- Entity Framework 使用sql语句分页(查询单表)
- SQL Server使用ROW_NUMBER进行快速分页查询
- spring boot使用原生sql分页查询以及两张表的内连接查询sql
- 使用srpingJPA进行分页,排序和模糊查询
- 组合查询——怎样使用窗口的继承达到事半功倍?
- Mybatis 使用Mapper接口的Sql动态代码方式进行CURD和分页查询
- 【Lucene】使用EasyUI和JQuery配合Lucene实现数据的分页查询以及高亮显示
- SQL多表查询中的分页,字段组合综合实例解析
- EasyUI使用心得——datagrid的查询功能和SubGrid冲突导致分页无效问题
- 在ORACLE 中使用Instr和Decode函数处理组合查询