介绍

介绍什么的,大家自己去下面的网站看 Bootstrap中文网:http://www.bootcss.com/        Bootstrap Table Demo:http://issues.wenzhixin.net.cn/bootstrap-table/index.html Bootstrap Table API:http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/ Bootstrap Table源码:https://github.com/wenzhixin/bootstrap-table Bootstrap DataPicker:http://www.bootcss.com/p/bootstrap-datetimepicker/ Boostrap Table 扩展API:http://bootstrap-table.wenzhixin.net.cn/extensions/

初始版本


首先在我们的html里加入

<div>
        <table id="goods_table" class="table table-hover"></table>
</div>

同时得引入下面的js与css

<link  href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.css" rel="stylesheet">
<link  href="css/bootstrap-table.min.css" rel="stylesheet">
<script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min.js"></script>
<script src="http://apps.bdimg.com/libs/respond.js/1.4.2/respond.js"></script>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="script/bootstrap-table.min.js"></script>
<script src="script/bootstrap-table-zh-CN.min.js"></script>
<script src="http://apps.bdimg.com/libs/jquery.cookie/1.4.1/jquery.cookie.js"></script>
<script src="script/handler.js" type="text/javascript"></script>

OK现在我们看看这个handler.js

//存放主要交互逻辑的js代码
$(function () {
	//初始化业务逻辑script
   loadGoods();
})

function loadGoods(){
	$('#goods_table')
	.bootstrapTable(
			{
				url : '/beauty_ssm_cluster/goods/list.do', // 请求后台的URL(*)
				method : 'get', // 请求方式(*)
				pagination : true,
				search : true, // 显示搜索框
				showToggle : true, // 是否显示详细视图和列表视图的切换按钮
				sidePagination : "server", // 服务端处理分页
				showColumns : true, // 是否显示所有的列
				showRefresh : true,// 是否显示刷新按钮

				columns : [
						{
							field : 'goodsId',
							title : '商品ID'
						},
						{
							field : 'title',
							title : '标题'
						},
						{
							field : 'price',
							title : '价格'
						},
						{
							field : 'state',
							title : '状态',
							formatter : function(value,
									row, index) {
								var ret = "";
								if (value == 0) {
									ret = "下架";
								}
								if (value == 1) {
									ret = "正常";
								}
								return ret;
							}
						},
						{
							field : 'number',
							title : '数量'
						},
						{
							field : 'goodsId',
							title : '操作',
							formatter : function(value,
									row, index) {
								var ret = '<button class="btn btn-info" onclick="handler.goodsBuy('
										+ value
										+ ');">购买</button> ';
								return ret;
							}
						}, ]
			});
}

这里我要说一下那个搜索框,在搜索框里写入数据后,js会直接把值传给后台,从后台取到结果后就直接刷新table我们再看看后台的处理逻辑

@RequestMapping(value = "/list", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public BootStrapTableResult<Goods> list(Integer offset, Integer limit,String search) {
		LOG.info("invoke----------/goods/list");
		offset = offset == null ? 0 : offset;//默认便宜0
		limit = limit == null ? 50 : limit;//默认展示50条
		List<Goods> list=null;
		System.out.println("search "+search);

		if (search==null) {
			list= goodsService.getGoodsList(offset, limit);
		}else {
			try {
				//这里得转码 否则会出问题 其实理论上 应该是前台做转码的
				search=new String(search.getBytes("iso8859-1"), "utf-8");
				System.out.println(search+" ppp ");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			list= goodsService.queryByField(offset, limit,search);
		}

		BootStrapTableResult<Goods> result= new BootStrapTableResult<Goods>(list);
		int count=goodsService.getGoodsCount(search);
		System.out.println("count: "+count);
		result.setTotal(count);
		return result;
	}

这个BootStrapTableResult里面有两个字段
private List<T> rows;
private int total;
total存放的数据的总量
最后后台向前台返回一个json

加搜索版


在html里加上
 <div class="panel-heading">查询条件</div>
            <div class="panel-body">
                <form id="formSearch" class="form-horizontal">
                    <div class="form-group" style="margin-top:15px">
                        <label class="control-label col-sm-1" for="txt_search_departmentname">部门名称</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="txt_search_departmentname">
                        </div>
                        <label class="control-label col-sm-1" for="txt_search_statu">状态</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="txt_search_statu">
                        </div>
                        <div class="col-sm-4" style="text-align:left;">
                            <button type="button" style="margin-left:50px" onclick="reloadTable()" id="btn_query" class="btn btn-primary">查询</button>
                        </div>
                    </div>
                </form>
            </div>
当然我们就得看看reloadTable是什么样的
$(function () {
	//初始化业务逻辑script
   loadGoods();
})
同时在bootstrapTable里面加上这个参数
queryParams: function (param) {
	var temp = {   
	    //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的
            limit: param.limit,   //页面大小
            offset: param.offset,  //页码
	    //我们吧#txt_search_departmentname里面的值以departmentname传到后台
            departmentname: $("#txt_search_departmentname").val(),
            statu: $("#txt_search_statu").val(),
            search:param.search
        };
        return temp;
},
例如

源码下载

https://github.com/cxyxd/beauty_ssm_cluster/archive/1.0.0.zip
从goodslist.html开始阅读


另外关于分页与查询大家可以看看这个组件
http://botmonster.com/jquery-bootpag
$('#page-selection').bootpag({
    total: ${totalPage},
    page: ${currentPage},
    maxVisible: 5,
    leaps: true,
    firstLastUse: true,
    first: '←',
    last: '→',
    wrapClass: 'pagination',
    activeClass: 'active',
    disabledClass: 'disabled',
    nextClass: 'next',
    prevClass: 'prev',
    lastClass: 'last',
    firstClass: 'first'
}).on("page",
function(event,num) {
    var url="getAllOpponent.action?byPage=ture&currentPage=" + num + "";
//    var type='${customer.type}';
//    var customerName='${customer.type}';
//    var clientName='${clientName}';
///    if(type!="")
//    <span style="white-space:pre">	</span>url+="customer.type="+type;
//    if(customerName!="")
//        url+="customer.name="+customerName;
//    if(clientName!="")
//        url+="clientName="+clientName;
//    alert(url);
    location.href = url;

});

参考资料

http://blog.csdn.net/song19890528/article/details/50299885http://www.jb51.net/article/60965.htm下面这个博客一定要看,我自己从这个博客里受益良多http://www.cnblogs.com/landeanfen/p/4976838.html?utm_source=tuicool&utm_medium=referral

Bootstarp-table入门的更多相关文章

  1. 关于Bootstrap table的回调onLoadSuccess()和onPostBody()使用小结

    关于Bootstrap table的回调onLoadSuccess()和onPostBody()使用小结 Bootstrap table 是一款基于 Bootstrap 的 jQuery 表格插件, ...

  2. day05-(validate&bootstred)

    网站分享: http://www.runoob.com/ 回顾: html:展示 文件 标签: <html> <head> <title></title> ...

  3. bootstrap-table 列拖动

    1.页面js/css <!-- bootstrap 插件样式 --> <link th:href="@{/common/bootstrap-3.3.6/css/bootst ...

  4. Windows Azure入门教学系列 (六):使用Table Storage

    本文是Windows Azure入门教学的第六篇文章. 本文将会介绍如何使用Table Storage.Table Storage提供给我们一个云端的表格结构.我们可以把他想象为XML文件或者是一个轻 ...

  5. bootstrap table教程--使用入门基本用法

    笔者在查询bootstrap table资料的时候,看了很多文章,发觉很多文章都写了关于如何使用bootstrap table的例子,当然最好的例子还是官网.但是对于某部分技术人员来说,入门还是不够详 ...

  6. [转]Windows Azure入门教学系列 (六):使用Table Storage

    本文转自:http://blogs.msdn.com/b/azchina/archive/2010/03/11/windows-azure-table-storage.aspx 本文是Windows ...

  7. BootStrap Table超好用的表格组件基础入门

    右侧导航条有目录哟,看着更方便 快速入门 表格构建 API简单介绍 主要研究功能介绍 快速入门 最好的资源官方文档 官方文档地址****https://bootstrap-table.com/docs ...

  8. iphone dev 入门实例1:Use Storyboards to Build Table View

    http://www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/ Creating Navig ...

  9. BootStrap入门教程 (二) :BASE CSS(排版(Typography),表格(Table),表单(Forms),按钮(Buttons))

    上讲回顾:Bootstrap的手脚架(Scaffolding)提供了固定(fixed)和流式(fluid)两种布局,它同时建立了一个宽达940px和12列的格网系统. 基于手脚架(Scaffoldin ...

  10. Uni2D 入门 -- Asset Table

    转载 http://blog.csdn.net/kakashi8841/article/details/17686791 Uni2D生成了一个自定义的表格用于保存你资源的唯一ID的引用.这个表格用于更 ...

随机推荐

  1. Linux服务器断电导致挂载及xfs文件损坏的修复方法

    系统文件损坏后进入紧急修复模式,无法进行维护工作 welcome to emergency mode!after logging in ,type "journalctl -xb" ...

  2. shell编程-邮件发送设置

    在linux 运维过程中,经常会写一些脚本监控一些服务器的状态,如监控redis 主从切换,redis 宕机等,当事件发生时,应该发送邮件通知到相对应的管理员,因此就需要搭建邮件服务,使linux 能 ...

  3. 在Linux(ubuntu 14.04)上部署WeX5跨平台App(HTML5)

    1. 前言   这篇文章讲述的是把毕业设计的用 WeX5 开发的项目部署到阿里云的Linux(ubuntu14.04)上,本来可以部署在WeX5自带的服务器上,但是WeX5的服务器我以前部署的项目突然 ...

  4. [HAOI2015]数字串拆分

    题目描述 你有一个长度为n的数字串.定义f(S)为将S拆分成若干个1~m的数的和的方案数,比如m=2时,f(4)=5,分别为4=1+1+1+1你可以将这个数字串分割成若干个数字(允许前导0),将他们加 ...

  5. [HNOI2008]遥远的行星

    题目描述 直线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量,故直观上说每颗行 ...

  6. 洛谷P3209 [HNOI2010]PLANAR

    首先用一波神奇的操作,平面图边数m<=3*n-6,直接把m降到n, 然后对于冲突的边一条环内,一条环外,可以用并查集或者2Sat做, 当然并查集是无向的,2Sat是有向的,显然用并查集比较好 复 ...

  7. NOIP2014-9-6模拟赛

    工资 (money/money.in/money.out) 时限1000ms 内存256MB 聪哥在暑假参加了打零工的活动,这个活动分为n个工作日,每个工作日的工资为Vi.有m个结算工钱的时间,聪哥可 ...

  8. 【bzoj4569 scoi2016】萌萌哒

    题目描述 一个长度为n的大数,用S1S2S3...Sn表示,其中Si表示数的第i位,S1是数的最高位,告诉你一些限制条件,每个条件表示为四个数,l1,r1,l2,r2,即两个长度相同的区间,表示子串S ...

  9. Nginx+uWSGI+Django环境配置

    通常项目会部署在虚拟环境,虚拟环境的使用可以参考这里,点击前往 当然你也可以直接部署,这里不多说. 一.安装uWSGI 1.通过pip安装 pip install uwsgi 这里只说明了一种安装方式 ...

  10. VS2012不能加载想要打开的项目/解决方案

    今天回宿舍用自己的电脑敲代码,想要打开之前的项目,可是VS2012打开之后项目却显示“无法加载” 查了之后才知道原来是由于某个安装包缺少引起的,具体做法请看如下 链接:http://jingyan.b ...