基于bootstrapTalbe查询,删除/批量删除 ,排序,搜索

限时加码!20+主流AI编程工具免费用 购周边加赠Coding Plan Lite,Claude Code、Cursor等即刻畅享,学习进阶更高效! 阅读详情


1.导入css,js

<link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">

<link href="../css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">

<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/bootstrap.min.js?v=3.3.6"></script>
<!-- Bootstrap table -->
<script src="../js/plugins/bootstrap-table/bootstrap-table.min.js"></script>

<script src="../js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>


2.html中直接写入

<div class="btn-group hidden-xs" id="toolbar" role="group">
<button type="button" class="btn btn-outline btn-default">
<i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
</button>


<button type="button" class="btn btn-outline btn-default" onclick="deleteMore()">
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
</button>
</div>

<table id="table"></table>


3.js

<script type="text/javascript">
//根据窗口调整表格高度
$(window).resize(function() {
$('#table').bootstrapTable('resetView', {
height : tableHeight()
})
})
//生成用户数据
$('#table')
.bootstrapTable(
{
method : 'post',
contentType : 'application/x-www-form-urlencoded',//必须要有
url : '/goods/selectAll',// 获取表格数据的url
height : tableHeight(),//高度调整
striped : true, //是否显示行间隔色
clickToSelect : false,//是否启用点击选中行
sidePagination : "server", //分页方式:client客户端分页,server服务端分页(*)
cache : false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
uniqueId : "id",//每一行指定唯一标识符
locale : 'zh-CN',//中文支持,
showRefresh : true,//是否启用刷新按钮
search:true,//是否启用搜索框
showColumns:true,//是否显示内容列下拉框。
toolbar : "#toolbar",
dataField : 'list',//bootstrap table 可以前端分页也可以后端分页,这里
//我们使用的是后端分页,后端分页时需返回含有total:总记录数 
//list: 记录集合 键值可以修改
queryParams : queryParams,//请求服务器时所传的参数
pagination : true, //是否显示分页(*)
pageNumber : 1, //初始化加载第一页,默认第一页
pageSize : 10, //每页的记录行数(*)
queryParamsType : "limit",
pageList : [ 10, 25, 50, 100 ], //可供选择的每页的行数(*)
queryParamsType : 'limit',//查询参数组织方式
sortOrder : 'asc',
columns : [
{
checkbox : true
},
{
title : 'id',
field : 'id',
visible : false,//显示或隐藏该列, 默认显示, False为隐藏
},
{
title : '商品名',
field : 'name',
align : 'center',
valign : 'middle',
},
{
title : '编号',
field : 'no',
align : 'center',
valign : 'middle',
},
{
title : '价格',
field : 'price',
align : 'center',
valign : 'middle',
sortable : true,//是否启用排序
},
{
title : '数量',
field : 'num',
align : 'center',
valign : 'middle',
sortable : true,//是否启用排序
},
{
title : '日期',
field : 'inputtime',
align : 'center',
valign : 'middle',
sortable : true,
},
{
title : '简介',
field : 'content',
align : 'center',
valign : 'middle',
},
{
title : "操作",
align : 'center',
valign : 'middle',
width : 160, // 定义列的宽度,单位为像素px
formatter : function(value, row, index) {
return '<button class="btn btn-info btn-sm" >编辑</button>&nbsp;&nbsp;'
+ '<button class="btn btn-danger btn-sm" onclick="deleteItem('
+ row.id
+ ')">删除</button>';
}
} ],

responseHandler : function(res) {
//在ajax获取到数据,渲染表格之前,修改数据源
return res;
}
})
//请求服务数据时所传参数
function queryParams(params) {
console.log(params)
return {
size : params.limit,
page : params.offset / params.limit + 1,
   text:params.sort,//排序字段
   paixu:params.order,// 排序方式
   name:params.search
   
     
}
}
//删除行
function deleteItem(id) {
swal({
title : "您确定要删除这条信息吗",
text : "删除后将无法恢复,请谨慎操作!",
type : "warning",
showCancelButton : true,
confirmButtonColor : "#DD6B55",
confirmButtonText : "删除",
closeOnConfirm : false
}, function() {
$('#table').bootstrapTable('removeByUniqueId', id);
$.post({
url : "/goods/deleteById",
data : {
id : id,
}
})
swal("删除成功!", "您已经永久删除了这条信息。", "success");
});
}
//批量删除
function deleteMore() {
swal({
title : "您确定要删除这些信息吗",
text : "删除后将无法恢复,请谨慎操作!",
type : "warning",
showCancelButton : true,
confirmButtonColor : "#DD6B55",
confirmButtonText : "删除",
closeOnConfirm : false
}, function() {
var arr = $('#table').bootstrapTable('getSelections');
for (var i = 0; i < arr.length; i++) {
$('#table')
.bootstrapTable('removeByUniqueId', arr[i].id);
$.post({
url : "/goods/deleteById",
data : {
id : arr[i].id,
}
})
}


swal("删除成功!", "您已经永久删除了这条信息。", "success");
});


}
//tableHeight函数
function tableHeight() {
//可以根据自己页面情况进行调整
return $(window).height() - 150;
}

</script>

4.Controller



@Controller
@RequestMapping("goods")
public class GoodsController {
@Autowired
private GoodsService service;

@RequestMapping("/")
    public String index(){
        return "goodsList";
    }

/*
* 根据条件查 参数:page size name text paixu
*/
@RequestMapping(value = { "selectAll" }, produces = "application/json;charset=UTF-8")
@ResponseBody
public Map selectAll(Pages pages,String name,String text,@RequestParam(defaultValue = "desc") String  paixu) {
Map<String, Object> map = new HashMap(5);
map.put("pages", pages);
map.put("name", name);
map.put("text", text);
map.put("paixu", paixu);
List<Goods> list=this.service.selectAll(map);
   Map<String, Object> resultMap = new HashMap<>();  
   resultMap.put("list",list);  
   resultMap.put("total",this.service.getCount(map));  
   return resultMap;
}



/*
* 删除
*/
@ResponseBody
@RequestMapping(value = { "deleteById" }, produces = "application/json;charset=UTF-8")
public void deleteProfessorByProid(int id){
this.service.deleteById(id);
}

5.mybaits

 <!-- 根据条件查询 -->
<select id="selectAll" resultMap="BaseResultMap">
select * from goods
<include refid="where-sql" />
order by
<if test="text=='name' or text==null ">
name ${paixu}
</if>
<if test="text=='price' ">
price ${paixu}
</if>
<if test="text=='num' ">
num ${paixu}
</if>
<if test="text=='inputtime' ">
inputtime ${paixu}
</if>
limit #{pages.begin},#{pages.size}
</select>
<sql id="where-sql">
<where>
<if test="name !=null and !&quot;&quot;.equals(name.trim())">
and name like '%' #{name} '%'
</if>

<if test="content !=null and !&quot;&quot;.equals(content.trim())">
and content like '%' #{content} '%'
</if>

</where>
</sql>
<!-- 查询结果数量 -->
<select id="getCount" resultType="Integer">
select count(*) from goods 
<include refid="where-sql" />
</select>

<!-- 删除 -->
<delete id="deleteById" parameterType="java.lang.Integer">
delete from goods
where id = #{id,jdbcType=INTEGER}

</delete>


6.源代码

https://download.csdn.net/download/t617ing/10439034

BootStrap Table 重写API实现 可对列选择性的搜索 下载地址:http://note.youdao.com/yws/public/redirect/share?id=a470bb9ede4466626edfea2946eb3553&type=false 阅读详情

相关推荐

bootstap-talbe日期格式化

bootstap-talbe日期格式化,包括mysql数据库,后台为spring mybatis

python测试开发django-127.bootstrap-table 如何给单元格添加功能按钮(编辑/删除) 和事件(events)

前言 在bootstrap-table表格最后一列添加操作按钮,可以添加编辑和删除按钮,方便操作单行数据。 添加编辑和删除按钮 在 columns 给操作按钮添加events事件,此代码需在初始化table表格前写 “click #editTable” 点击#editTable button按钮,触发对应的事件,可以传四个参数e, value, row, index “click #deleteTable” 点击#deleteTable button按钮,触发对应的事件,可以传四个参数e, value

qq_27371025的博客 1971

16A.rar

当 CAD 缺失对应字体时,图纸文字会显示异常,出现乱码、问号。将下载好的字体文件复制到 AutoCAD 的 Fonts 文件夹中,即可恢复正常显示。

bootstrap表格分页删除页面最后一条数据,展示异常问题

问题:通过bootstrap Table进行表格展示的时候,如果数据有多页,将最后一页的数据全部删除,数据删除后应当回到上一页,但删除刷新后,还是处在当前页,就会造成无数据的问题。 解决方法:修改bootstrap-table.js源码,如下: success: function (res) { /**新加的代码,top*/ if(that...

weixin_39370907的博客 794

bootstrap table表格去掉排序箭头

在bootstrap table表格插件里面,会有这样的排序箭头,可以将表格的内容按照一定的顺序排列,无论是需要或者不需要,都可以通过一个属性来控制sortable 。 当sortable : true的时候,则会出现排序箭头,当注释这行代码的时候,则表格不会出现排序箭头。 { title : '设备编号', field...

祈澈菇凉 3518

BootStrap Table序号翻页后重置

解决 BootStrap Table 每次翻页 序号都从1开始          { field: 'name', title: '序号', width: 250, align: 'center', formatter: function ...

a314753967的博客 936

20180415开发笔记 bootstrap table在查询时刷新表格查询后端数据时可以再次加入查询字符串数据

function customSearch(text) { $('#table').bootstrapTable('refresh');//刷新Table,Bootstrap Table 会自动执行重新查询 } function newSearch(text) { $('#table').bootstra...

孤风寂影 1053

Bootstrap-Table中给一列数据中添加查看修改删除

Bootstrap-Table中给一列数据中添加查看、修改、删除功能 只需要在columns中的表格参数中加入这段代码即可: { field: 'operator', title: '操作', align: 'center', sortable: true, width:'6%', formatter: functio

qq_45668217的博客 1416

bootstrap前端开发实现分页查询

使用bootstrap实现分页效果,因为它比easyUI要好看的多。分三大步完成:引入css样式,html代码、js控制代码。

802

超详细bootstraptable使用教程

首先附上本人有道云笔记链接,内含插件下载以及详细解读 bootstraptable下载及使用 1、引用顺序 2、body部分 <div> //这边是定义表格左上角的按钮 <div id="toolbar"> <button class="Export" title="Export Excel" ...

墨水直达的博客 2793

bootstrapTable清空search框内容并刷新页面

let tableNode = $("#tableSelector"); tableNode.bootstrapTable("resetSearch",""); tableNode.bootstrapTable('refresh'); 参考: https://github.com/wenzhixin/bootstrap-table/issues/1230 https://stackoverflow.com/questions/53177296/clear-filter-values-in-boots.

Jalen备忘录 1692

bootstrap学习(五):跟着宝哥学java:bootstrap批量删除

bootstrap学习(五):跟着宝哥学java:bootstrap批量删除

跟着宝哥学java的博客 1295

Bootstrap Table强大的web数据表格渲染框架

Bootstrap Table 是一款完全兼容 Bootstrap 3/4 的 JavaScript 表格插件,通过 HTML5 data 属性与 JavaScript 配置的双重驱动,实现了响应式表格的快速开发。零侵入性:无需修改 Bootstrap 原生样式,支持渐进式集成组件化架构:基础功能与扩展插件分离,支持按需加载标准化交互:遵循 Bootstrap 设计规范,确保用户体验一致性跨平台适配:自动适应 PC 端与移动端的屏幕尺寸变化自适应布局:通过启用智能列隐藏,移动端自动切换为堆叠视图。

weixin_40345119的博客 125

Bootstrap-table 自我留存

一、什么是Bootstrap-table?   在业务系统开发中,对表格记录的查询、分页、排序等处理是非常常见的,在Web开发中,可以采用很多功能强大的插件来满足要求,且能极大的提高开发效率,本随笔介绍这个bootstrap-table是一款非常有名的开源表格插件,在很多项目中广泛的应用。Bootstrap-table插件提供了非常丰富的属性设置,可以实现查询、分页、排序、复选框、设置显示列、Card view视图、主从表显示、合并列、国际化处理等处理功能,而且该插件同时也提供了一些不错的扩展功能,如..

Rebirth 重生 1万+

Bootstrap常用、实用整理(bootstrap踩过的坑),持续更新......

bootstrap是一个响应式前段框架、丰富的插件。可以提高开发效率,前段时间项目中用到了bootstrap在这里我记录下项目中用到的东西及我的理解(我只是一个小白),希望大家多多指正、共同学习。 在这里我要介绍下常用的、比如bootstrap suggest、及bootstrap table。 bootstrap table 、表格插件。丰富的API,满足绝大多数需求。 先来一个boots...

Durian大圣 2704

Bootstrap表格插件--bootstrap-table

一、简介 bootstrap-table是基于 Bootstrap 的 jQuery 表格插件,通过简单的设置,就可以拥有强大的单选、多选、排序、分页,以及编辑、导出、过滤(扩展)等等的功能。 官网地址: http://bootstrap-table.wenzhixin.net.cn/zh-cn/ Github地址: https://github.com/wenz

fendo 5656
下一篇: 基于Flot的折线图
T617ing
博客等级 码龄11年 1粉丝 6原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值