BootStrap 表格神器

本文详细介绍如何结合BootstrapTable和jQueryUI实现优雅的前端表格展示,包括数据分页、编辑和导出为Excel等功能,同时提供了完整的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

jquery uibootstrap 最好不过。 bootstrap作为当下最火的前端框架,以其极简主义吸引着各路开发者选用。 而 bootstrapTable 作为一款前端表格插件,延续了bootstrap的风格样式,继承了jquery简单易用的特性。 需引入: [code lang="js"]jquery.min.js bootstrap.min.js bootstrap-table.js bootstrap-table-zh-CN.js [/code]
前台demo 这里要特别注意的是, field值得与数据库“列名”对应 sidePagination:"client" 表示客户端处理分页,小网站上千条数据没啥问题,数据量大须服务器端处理分页。 [code lang="js"] $('#table2').bootstrapTable({ url:'../manager.action',//servlet地址 dataType:"json",//数据类型 contentType: "application/x-www-form-urlencoded", method: 'get', pagination: true, //分页 singleSelect:false,//是否单选 striped: true,     //使表格带有条纹 pagination: true,    //在表格底部显示分页工具栏 pageSize:6,//每页显示条数 pageNumber:1, queryParams:'op=showUser',//参数 showColumns: true, showRefresh: true,//显示刷新控件 pageList: [5, 6, 7],//可选分页条数 uniqueId: "ID", minimumCountColumns: 2, clickToSelect: true, smartDisplay:true, sidePagination:"client",//客户端处理分页    服务器端处理用server columns: [{ field:'fid', title:'商品编号' }, { field:'fname', title:'商品名称', editable:true }, { field:'normprice', title:'原价', editable:true },{ field:'realprice', title:'现价', editable:true }, { field:'detail', title:'详情', editable:true }, { field:'fphoto', title:'图片', formatter:function(value,row,index){ var d = '<img src="../images/'+value+'" width="40px" height="30px" /> return d; } }, { field: 'operate', title: '操作', align: 'center', width: 100, formatter:function(value,row,index){ var d = &lt;&gt;'button class="btn btn-info" style="text-shadow: black 5px 3px 3px;" type="button"修改'; return d; } }, ] });[/code]
servlet端,dopost分发,op操作: [code lang="java"] Listlist =db.findfood(); Gson jb = new Gson(); PrintWriter out; out=response.getWriter(); out.println(jb.toJson(list)); out.flush(); out.close(); [/code] 最近又有新需求,想把网页的表格以excl导出来,而用bootStrap -table 就特别简单得让人难以置信了。 需新增 [code lang="js"] bootstrap-table-export.min.js js/tableExport.js js/jquery.base64.js[/code] 再在bootstrapTable( {中显示导出控件 [code lang="js"] showExport: true, //是否显示导出 exportDataType: "basic" //包含json,sql,excl等等诸多格式 [/code] 最终结果: TES]~QCEU}38@W7VSS3$SN6

转载于:https://my.oschina.net/u/3090863/blog/796319

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值