search
HomeWeb Front-endBootstrap TutorialA brief discussion on two ways to implement bootstrap table paging

This article will introduce to you two ways to implement bootstrap table paging. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

A brief discussion on two ways to implement bootstrap table paging

Two ways of bootstrap table paging:

Front-end paging: Query all data from the database at one time and perform it on the front-end Paging (front-end paging can be used when the amount of data is small or the logic processing is not complex)

Server paging: only query the pieces of data required for loading the current page each time

bootstrap download address :http://www.bootcss.com/

bootstrap-table Download address: http://bootstrap-table.wenzhixin.net.cn/

jquery Download address: http:/ /www.jq22.com/jquery-info122

Paging effect (please ignore the style)

1: Prepare js, css and other files

Put the downloaded document directly into the webapp directory

Introduce the required js and css into the page

<!-- 引入的css文件  -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="bootstrap-table/dist/bootstrap-table.min.css"
	rel="stylesheet">
<!-- 引入的js文件 -->
<script src="jquery/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="bootstrap-table/dist/bootstrap-table.min.js"></script>
<script src="bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>

[Related recommendations : "bootstrap tutorial"】

2: HTML page tag content

<div class="panel panel-default">
    <div class="panel-heading">
        查询条件
    </div>
    <div class="panel-body form-group" style="margin-bottom:0px;">
        <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">姓名:</label>
        <div class="col-sm-2">
            <input type="text" class="form-control" name="Name" id="search_name"/>
        </div>
        <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">手机号:</label>
        <div class="col-sm-2">
            <input type="text" class="form-control" name="Name" id="search_tel"/>
        </div>
        <div class="col-sm-1 col-sm-offset-4">
            <button class="btn btn-primary" id="search_btn">查询</button>
        </div>
     </div>
</div>
<table id="mytab" class="table table-hover"></table>

3: JS paging code

$(&#39;#mytab&#39;).bootstrapTable({
	method : &#39;get&#39;,
	url : "user/getUserListPage",//请求路径
	striped : true, //是否显示行间隔色
	pageNumber : 1, //初始化加载第一页
	pagination : true,//是否分页
	sidePagination : &#39;client&#39;,//server:服务器端分页|client:前端分页
	pageSize : 4,//单页记录数
	pageList : [ 5, 10, 20, 30 ],//可选择单页记录数
	showRefresh : true,//刷新按钮
	queryParams : function(params) {//上传服务器的参数
		var temp = {//如果是在服务器端实现分页,limit、offset这两个参数是必须的
			limit : params.limit, // 每页显示数量
			offset : params.offset, // SQL语句起始索引
			//page : (params.offset / params.limit) + 1, //当前页码 
 
			Name : $(&#39;#search_name&#39;).val(),
			Tel : $(&#39;#search_tel&#39;).val()
		};
		return temp;
	},
	columns : [ {
		title : &#39;登录名&#39;,
		field : &#39;loginName&#39;,
		sortable : true
	}, {
		title : &#39;姓名&#39;,
		field : &#39;name&#39;,
		sortable : true
	}, {
		title : &#39;手机号&#39;,
		field : &#39;tel&#39;,
	}, {
		title : &#39;性别&#39;,
		field : &#39;sex&#39;,
		formatter : formatSex,//对返回的数据进行处理再显示
	}, {
		title : &#39;操作&#39;,
		field : &#39;id&#39;,
		formatter : operation,//对资源进行操作
	} ]
})
 
//value代表该列的值,row代表当前对象
function formatSex(value, row, index) {
	return value == 1 ? "男" : "女";
	//或者 return row.sex == 1 ? "男" : "女";
}
 
//删除、编辑操作
function operation(value, row, index) {
	var htm = "<button>删除</button><button>修改</button>"
	return htm;
}
 
//查询按钮事件
$(&#39;#search_btn&#39;).click(function() {
	$(&#39;#mytab&#39;).bootstrapTable(&#39;refresh&#39;, {
		url : &#39;user/getUserListPage&#39;
	});
})

Four: bootstrap-table implements front-end paging

Modify some attributes in the JS paging code

sidePagination:&#39;client&#39;,
queryParams : function (params) {
        var temp = {
            name:$(&#39;#search_name&#39;).val(),
            tel:$(&#39;#search_tel&#39;).val()
        };
        return temp;
    },

Define user object

package com.debo.common;
 
public class User {
	
	private Integer id;
	private String loginName;
	private String name;
	private String tel;
	private Integer sex;
	
        //省略Get/Set函数
}

Server Controller layer code

/**
*直接一次性查出所有的数据,返回给前端,bootstrap-table自行分页
*/
@RequestMapping("/getUserListPage")
@ResponseBody
public List<User> getUserListPage(User user,HttpServletRequest request){
	List<User> list = userService.getUserListPage(user);
	return list;
}

mabatis statement

<select id="getUserListPage" resultType="com.debo.common.User">
	SELECT * FROM user WHERE 1 = 1
	<if test="name!=null and name !=&#39;&#39;">
		AND name LIKE CONCAT(&#39;%&#39;,#{name},&#39;%&#39;)
	</if>
	<if test="tel!=null and tel !=&#39;&#39;">
		AND tel = #{tel}
	</if>
</select>

5: bootstrap-table implements server-side paging

Set certain attributes in the JS paging code

sidePagination:&#39;server&#39;,
queryParams : function (params) {
    var temp = {
        limit : params.limit, // 每页显示数量
        offset : params.offset, // SQL语句起始索引
        page: (params.offset / params.limit) + 1,   //当前页码
            
        Name:$(&#39;#search_name&#39;).val(),
        Tel:$(&#39;#search_tel&#39;).val()
    };
    return temp;
},

Encapsulate the public page object and let the user object inherit the page object

package com.debo.common;
 
public class Page {
	//每页显示数量
	private int limit;
	//页码
	private int page;
	//sql语句起始索引
	private int offset;
	public int getLimit() {
		return limit;
	}
	public void setLimit(int limit) {
		this.limit = limit;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getOffset() {
		return offset;
	}
	public void setOffset(int offset) {
		this.offset = offset;
	}
 
}
package com.debo.common;
 
public class User extends Page{
	
	private Integer id;
	private String loginName;
	private String name;
	private String tel;
	private Integer sex;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getLoginName() {
		return loginName;
	}
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public Integer getSex() {
		return sex;
	}
	public void setSex(Integer sex) {
		this.sex = sex;
	}
}

Encapsulate the returned data entity class

package com.debo.common;
 
import java.util.ArrayList;
import java.util.List;
 
public class PageHelper<T> {
    //实体类集合
    private List<T> rows = new ArrayList<T>();
    //数据总条数
    private int total;
 
    public PageHelper() {
        super();
    }
 
    public List<T> getRows() {
        return rows;
    }
 
    public void setRows(List<T> rows) {
        this.rows = rows;
    }
 
    public int getTotal() {
        return total;
    }
 
    public void setTotal(int total) {
        this.total = total;
    }
 
}

Server Controller layer code

@RequestMapping("/getUserListPage")
@ResponseBody
public PageHelper<User> getUserListPage(User user,HttpServletRequest request) {
		
        PageHelper<User> pageHelper = new PageHelper<User>();
	// 统计总记录数
	Integer total = userService.getTotal(user);
	pageHelper.setTotal(total);
 
	// 查询当前页实体对象
	List<User> list = userService.getUserListPage(user);
	pageHelper.setRows(list);
 
	return pageHelper;
}

mybatis statement

<select id="getTotal" resultType="int">
	SELECT count(1) FROM user WHERE 1 = 1
	<if test="name!=null and name !=&#39;&#39;">
		AND name LIKE CONCAT(&#39;%&#39;,#{name},&#39;%&#39;)
	</if>
	<if test="tel!=null and tel !=&#39;&#39;">
		AND tel = #{tel}
	</if>
</select>
 
<select id="getUserListPage" resultType="com.debo.common.User">
	SELECT * FROM user WHERE 1 = 1
	<if test="name!=null and name !=&#39;&#39;">
		AND name LIKE CONCAT(&#39;%&#39;,#{name},&#39;%&#39;)
	</if>
	<if test="tel!=null and tel !=&#39;&#39;">
		AND tel = #{tel}
	</if>
	LIMIT #{offset},#{limit}
</select>

tip: Reload the table after adding, deleting, or modifying operations

$("#mytab").bootstrapTable(&#39;refresh&#39;, {url : url});

For more programming-related knowledge, please visit:Programming Teaching! !

The above is the detailed content of A brief discussion on two ways to implement bootstrap table paging. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete
Bootstrap: A Quick Guide to Web FrameworksBootstrap: A Quick Guide to Web FrameworksApr 15, 2025 am 12:10 AM

Bootstrap is a framework developed by Twitter to help quickly build responsive, mobile-first websites and applications. 1. Ease of use and rich component libraries make development faster. 2. The huge community provides support and solutions. 3. Introduce and use class names to control styles through CDN, such as creating responsive grids. 4. Customizable styles and extension components. 5. Advantages include rapid development and responsive design, while disadvantages are style consistency and learning curve.

Breaking Down Bootstrap: What It Is and Why It MattersBreaking Down Bootstrap: What It Is and Why It MattersApr 14, 2025 am 12:05 AM

Bootstrapisafree,open-sourceCSSframeworkthatsimplifiesresponsiveandmobile-firstwebsitedevelopment.Itofferspre-styledcomponentsandagridsystem,streamliningthecreationofaestheticallypleasingandfunctionalwebdesigns.

Bootstrap: Making Web Design EasierBootstrap: Making Web Design EasierApr 13, 2025 am 12:10 AM

What makes web design easier is Bootstrap? Its preset components, responsive design and rich community support. 1) Preset component libraries and styles allow developers to avoid writing complex CSS code; 2) Built-in grid system simplifies the creation of responsive layouts; 3) Community support provides rich resources and solutions.

Bootstrap's Impact: Accelerating Web DevelopmentBootstrap's Impact: Accelerating Web DevelopmentApr 12, 2025 am 12:05 AM

Bootstrap accelerates web development, and by providing predefined styles and components, developers can quickly build responsive websites. 1) It shortens development time, such as completing the basic layout within a few days in the project. 2) Through Sass variables and mixins, Bootstrap allows custom styles to meet specific needs. 3) Using the CDN version can optimize performance and improve loading speed.

Understanding Bootstrap: Core Concepts and FeaturesUnderstanding Bootstrap: Core Concepts and FeaturesApr 11, 2025 am 12:01 AM

Bootstrap is an open source front-end framework, and its main function is to help developers quickly build responsive websites. 1) It provides predefined CSS classes and JavaScript plug-ins to facilitate the implementation of complex UI effects. 2) The working principle of Bootstrap relies on its CSS and JavaScript components to realize responsive design through media queries. 3) Examples of usage include basic usage, such as creating buttons, and advanced usage, such as custom styles. 4) Common errors include misspelling of class names and incorrectly introducing files. It is recommended to use browser developer tools to debug. 5) Performance optimization can be achieved through custom build tools, best practices include predefined using semantic HTML and Bootstrap

Bootstrap Deep Dive: Responsive Design & Advanced Layout TechniquesBootstrap Deep Dive: Responsive Design & Advanced Layout TechniquesApr 10, 2025 am 09:35 AM

Bootstrap implements responsive design through grid systems and media queries, making the website adapted to different devices. 1. Use a predefined class (such as col-sm-6) to define the column width. 2. The grid system is based on 12 columns, and it is necessary to note that the sum does not exceed 12. 3. Use breakpoints (such as sm, md, lg) to define the layout under different screen sizes.

Bootstrap Interview Questions: Land Your Dream Front-End JobBootstrap Interview Questions: Land Your Dream Front-End JobApr 09, 2025 am 12:14 AM

Bootstrap is an open source front-end framework for rapid development of responsive websites and applications. 1. It provides the advantages of responsive design, consistent UI components and rapid development. 2. The grid system uses flexbox layout, based on 12-column structure, and is implemented through classes such as .container, .row and .col-sm-6. 3. Custom styles can be implemented by modifying SASS variables or overwriting CSS. 4. Commonly used JavaScript components include modal boxes, carousel diagrams and folding. 5. Optimization performance can be achieved by loading only necessary components, using CDN, and compressing merge files.

Bootstrap & JavaScript Integration: Dynamic Features & FunctionalityBootstrap & JavaScript Integration: Dynamic Features & FunctionalityApr 08, 2025 am 12:10 AM

Bootstrap and JavaScript can be seamlessly integrated to give web pages dynamic functionality. 1) Use JavaScript to manipulate Bootstrap components, such as modal boxes and navigation bars. 2) Ensure jQuery loads correctly and avoid common integration problems. 3) Achieve complex user interaction and dynamic effects through event monitoring and DOM operations.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.