search
HomeWeb Front-endHTML TutorialBootstrap Table使用分享_html/css_WEB-ITnose

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

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

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

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

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

一、效果展示

二、BootStrap table简单介绍

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

三、使用方法

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>

2、table数据填充

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

<table data-toggle="table">    <thead>        ...    </thead></table>

...

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

第二种方式交第一种而言在处理复杂数据时更为灵活,一般使用第二种方式来进行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;	};

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");//通过此方法获取前端数据        ...

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

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

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());       ...

5、分页界面内容介绍

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

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

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

...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;//第几页...

四、其他

Bootstrap3兼容IE8浏览器

Statement
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
HTML vs. CSS and JavaScript: Comparing Web TechnologiesHTML vs. CSS and JavaScript: Comparing Web TechnologiesApr 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 as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 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.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 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: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 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 OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 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: 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.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 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.

See all articles

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 Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function