Table of Contents
最近客户提出需求,想将原有的管理系统,做下优化,通过手机也能很好展现,想到2个方案:
一、效果展示
二、BootStrap table简单介绍
三、使用方法
四、其他
Home Web Front-end HTML Tutorial Bootstrap Table使用分享_html/css_WEB-ITnose

Bootstrap Table使用分享_html/css_WEB-ITnose

Jun 21, 2016 am 08:57 AM

版权声明:本文为博主原创文章,未经博主允许不得转载。
Copy after login

最近客户提出需求,想将原有的管理系统,做下优化,通过手机也能很好展现,想到2个方案:

a方案:保留原有的页面,新设计一套适合手机的页面,当手机访问时,进入m.zhy.com(手机页面),pc设备访问时,进入www.zhy.com(pc页面)

b方案:采用bootstrap框架,替换原有页面,自动适应手机、平板、PC 设备

采用a方案,需要设计一套界面,并且要得重新写适合页面的接口,考虑到时间及成本问题,故项目采用了b方案

一、效果展示

二、BootStrap table简单介绍

bootStrap table 是一个轻量级的table插件,使用AJAX获取JSON格式的数据,其分页和数据填充很方便,支持国际化
Copy after login

三、使用方法

1、引入js、css

<!--css样式--><link href="css/bootstrap/bootstrap.min.css" rel="stylesheet"><link href="css/bootstrap/bootstrap-table.css" rel="stylesheet"><!--js--><script src="js/bootstrap/jquery-1.12.0.min.js" type="text/javascript"></script><script src="js/bootstrap/bootstrap.min.js"></script><script src="js/bootstrap/bootstrap-table.js"></script><script src="js/bootstrap/bootstrap-table-zh-CN.js"></script>
Copy after login

2、table数据填充

bootStrap table获取数据有两种方式,一是通过table 的data-url属性指定数据源,二是通过JavaScript初始化表格时指定url来获取数据

<table data-toggle="table">    <thead>        ...    </thead></table>
Copy after login

...

$('#table').bootstrapTable({          url: 'data.json'  });
Copy after login

第二种方式交第一种而言在处理复杂数据时更为灵活,一般使用第二种方式来进行table数据填充。

$(function () {	    //1.初始化Table	    var oTable = new TableInit();	    oTable.Init();	    //2.初始化Button的点击事件	    /* var oButtonInit = new ButtonInit();	    oButtonInit.Init(); */	});	var TableInit = function () {	    var oTableInit = new Object();	    //初始化Table	    oTableInit.Init = function () {	        $('#tradeList').bootstrapTable({	            url: '/VenderManager/TradeList',         //请求后台的URL(*)	            method: 'post',                      //请求方式(*)	            toolbar: '#toolbar',                //工具按钮用哪个容器	            striped: true,                      //是否显示行间隔色	            cache: false,                       //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)	            pagination: true,                   //是否显示分页(*)	            sortable: false,                     //是否启用排序	            sortOrder: "asc",                   //排序方式	            queryParams: oTableInit.queryParams,//传递参数(*)	            sidePagination: "server",           //分页方式:client客户端分页,server服务端分页(*)	            pageNumber:1,                       //初始化加载第一页,默认第一页	            pageSize: 50,                       //每页的记录行数(*)	            pageList: [10, 25, 50, 100],        //可供选择的每页的行数(*)	            strictSearch: true,	            clickToSelect: true,                //是否启用点击选中行	            height: 460,                        //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度	            uniqueId: "id",                     //每一行的唯一标识,一般为主键列	            cardView: false,                    //是否显示详细视图	            detailView: false,                   //是否显示父子表	            columns: [{	                field: 'id',	                title: '序号'	            }, {	                field: 'liushuiid',	                title: '交易编号'	            }, {	                field: 'orderid',	                title: '订单号'	            }, {	                field: 'receivetime',	                title: '交易时间'	            }, {	                field: 'price',	                title: '金额'	            }, {	                field: 'coin_credit',	                title: '投入硬币'	            },  {	                field: 'bill_credit',	                title: '投入纸币'	            },  {	                field: 'changes',	                title: '找零'	            }, {	                field: 'tradetype',	                title: '交易类型'	            },{	                field: 'goodmachineid',	                title: '货机号'	            },{	                field: 'inneridname',	                title: '货道号'	            },{	                field: 'goodsName',	                title: '商品名称'	            }, {	                field: 'changestatus',	                title: '支付'	            },{	                field: 'sendstatus',	                title: '出货'	            },]	        });	    };	    //得到查询的参数	  oTableInit.queryParams = function (params) {	        var temp = {   //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的	            limit: params.limit,   //页面大小	            offset: params.offset,  //页码	            sdate: $("#stratTime").val(),	            edate: $("#endTime").val(),	            sellerid: $("#sellerid").val(),	            orderid: $("#orderid").val(),	            CardNumber: $("#CardNumber").val(),	            maxrows: params.limit,	            pageindex:params.pageNumber,	            portid: $("#portid").val(),	            CardNumber: $("#CardNumber").val(),	            tradetype:$('input:radio[name="tradetype"]:checked').val(),	            success:$('input:radio[name="success"]:checked').val(),	        };	        return temp;	    };	    return oTableInit;	};
Copy after login

field字段必须与服务器端返回的字段对应才会显示出数据。

3、后台获取数据

a、servlet获取数据

BufferedReader bufr =  new BufferedReader(	new InputStreamReader(request.getInputStream(),"UTF-8"));	StringBuilder sBuilder = new StringBuilder("");	String temp = "";	while((temp = bufr.readLine()) != null){	       sBuilder.append(temp);	  }	bufr.close();	String json = sBuilder.toString();	JSONObject json1 = JSONObject.fromObject(json);	String sdate= json1.getString("sdate");//通过此方法获取前端数据        ...
Copy after login

b、springMvc Controller里面对应的方法获取数据

public JsonResult GetDepartment(int limit, int offset, string orderId, string SellerId,PortId,CardNumber,Success,maxrows,tradetype){ ...}
Copy after login

4、分页(遇到问题最多的)

使用分页,server端返回的数据必须包括rows和total,代码如下:

...gblst = SqlADO.getTradeList(sql,pageindex,maxrows);JSONArray jsonData=new JSONArray();		JSONObject jo=null;		for (int i=0,len=gblst.size();i<len;i++) 		{			TradeBean tb = gblst.get(i);			if(tb==null)			{				continue;			}			jo=new JSONObject();			jo.put("id",  i+1);			jo.put("liushuiid", tb.getLiushuiid());			jo.put("price", String.format("%1.2f",tb.getPrice()/100.0));			jo.put("mobilephone", tb.getMobilephone());			jo.put("receivetime", ToolBox.getYMDHMS(tb.getReceivetime()));			jo.put("tradetype", clsConst.TRADE_TYPE_DES[tb.getTradetype()]);			jo.put("changestatus", (tb.getChangestatus()!=0)?"成功":"失败");			jo.put("sendstatus", (tb.getSendstatus()!=0)?"成功":"失败");			jo.put("bill_credit", String.format("%1.2f",tb.getBill_credit()/100.0));                        jo.put("changes",String.format("%1.2f",tb.getChanges()/100.0));			jo.put("goodroadid", tb.getGoodroadid());			jo.put("SmsContent", tb.getSmsContent());			jo.put("orderid", tb.getOrderid());			jo.put("goodsName", tb.getGoodsName());			jo.put("inneridname", tb.getInneridname());			jo.put("xmlstr", tb.getXmlstr());						jsonData.add(jo);		}		int TotalCount=SqlADO.getTradeRowsCount(sql);		JSONObject jsonObject=new JSONObject();		jsonObject.put("rows", jsonData);//JSONArray		jsonObject.put("total",TotalCount);//总记录数		out.print(jsonObject.toString());       ...
Copy after login

5、分页界面内容介绍

前端获取分页数据,代码如下:

...oTableInit.queryParams = function (params) {            var temp = {   //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的                limit: params.limit,   //第几条记录                offset: params.offset,  //显示一页多少记录                sdate: $("#stratTime").val(),            };            return temp;        };...
Copy after login

后端获取分页数据,代码如下:

...int pageindex=0;int offset = ToolBox.filterInt(json1.getString("offset"));int limit = ToolBox.filterInt(json1.getString("limit"));	if(offset !=0){    pageindex = offset/limit;}    pageindex+= 1;//第几页...
Copy after login

四、其他

Bootstrap3兼容IE8浏览器

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative Overview HTML vs. CSS vs. JavaScript: A Comparative Overview Apr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Building the Structure of Web Pages HTML: Building the Structure of Web Pages Apr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML vs. CSS and JavaScript: Comparing Web Technologies HTML vs. CSS and JavaScript: Comparing Web Technologies Apr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML: Is It a Programming Language or Something Else? HTML: Is It a Programming Language or Something Else? Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

From Text to Websites: The Power of HTML From Text to Websites: The Power of HTML Apr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

See all articles