The editor of this article will take you from scratch and tell you step by step how to use the bootstrap Table plug-in to display a table on the front end
First, download the bootstrap Table plug-in Necessary js, address: https://github.com/wenzhixin/bootstrap-table
Official document address: http://bootstrap-table.wenzhixin.net .cn/zh-cn/documentation/
Recommended tutorial: bootstrap tutorial
The editor has circled the points that need attention in this article with a red pen
Show the renderings first
Then start using the bootstrap Table plug-in to create Table
Put the plug-in js downloaded from the above address into the project, which are js, css, fonts
There is a detail here: The name of the locale folder cannot be modified, and all language js inside must be pasted in. This article uses MVC as an example, of course WebForm is also possible
Usage steps:
1. Create a new controller and view, which references the _Layout master version
2. Reference the corresponding js in the view
Write a table table container on the page. This sentence must contain
<table id="ArbetTable"></table>
3. Initialize bootstrap Table
##
$(function () { //1.初始化Table var oTable = new TableInit(); oTable.Init(); });
4. Use bootstrap Table
var TableInit = function () { var oTableInit = new Object(); //初始化Table oTableInit.Init = function () { $('#ArbetTable').bootstrapTable({ url: '/Interface/GetData', //请求后台的URL(*) method: 'get', //请求方式(*) toolbar: '#toolbar', //工具按钮用哪个容器 striped: true, //是否显示行间隔色 cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*) pagination: true, //是否显示分页(*) sortable: false, //是否启用排序 sortOrder: "asc", //排序方式 queryParams: oTableInit.queryParams,//传递参数(*) sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*) pageNumber: 1, //初始化加载第一页,默认第一页 pageSize: 10, //每页的记录行数(*) pageList: [10, 25, 50, 100], //可供选择的每页的行数(*) search: true, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大 contentType: "application/x-www-form-urlencoded", strictSearch: true, showColumns: true, //是否显示所有的列 showRefresh: true, //是否显示刷新按钮 minimumCountColumns: 2, //最少允许的列数 clickToSelect: true, //是否启用点击选中行 height: 700, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度 uniqueId: "no", //每一行的唯一标识,一般为主键列 showToggle: true, //是否显示详细视图和列表视图的切换按钮 cardView: false, //是否显示详细视图 detailView: false, //是否显示父子表 columns: [ { field: 'ID', title: 'ID' }, { field: 'Name', title: '名字' }, { field: 'Sex', title: '性别' }, { field: 'operate', title: '操作', formatter: operateFormatter //自定义方法,添加操作按钮 }, ], rowStyle: function (row, index) { var classesArr = ['success', 'info']; var strclass = ""; if (index % 2 === 0) {//偶数行 strclass = classesArr[0]; } else {//奇数行 strclass = classesArr[1]; } return { classes: strclass }; },//隔行变色 }); }; //得到查询的参数 oTableInit.queryParams = function (params) { var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的 limit: params.limit, //页面大小 offset:params.offset }; return temp; }; return oTableInit; }; function operateFormatter(value, row, index) {//赋予的参数 return [ '<a class="btn active disabled" href="#">编辑</a>', '<a class="btn active" href="#">档案</a>', '<a class="btn btn-default" href="#">记录</a>', '<a class="btn active" href="#">准入</a>' ].join(''); }
4. Backend url returns data
public ActionResult GetData(int limit, int offset) { var data = new List<object>(){new { ID=1, Name="Arbet", Sex="男"}, new { ID= 2, Name="Arbet1", Sex="女" }, new {ID=3, Name="Arbet2",Sex="男" }, new {ID=4, Name="Arbet3",Sex="女" }, new {ID=5, Name="Arbet4",Sex="男" }, new {ID=6, Name="Arbet5",Sex="男" }, new {ID=7, Name="Arbet6",Sex="女" }, new {ID=8, Name="Arbet7",Sex="男" }, new { ID=9, Name="Arbet1", Sex="女" }, new {ID=10, Name="Arbet2",Sex="男" }, new {ID=11, Name="Arbet3",Sex="女" }, new {ID=12, Name="Arbet4",Sex="男" }, new {ID=13, Name="Arbet5",Sex="男" }, new {ID=14, Name="Arbet6",Sex="女" }, new {ID=15, Name="Arbet7",Sex="男" } }; var total = data.Count; var rows = data.Skip(offset).Take(limit).ToList(); return Json(new { total = total, rows = rows }, JsonRequestBehavior.AllowGet); }In this article, the blogger sets the data with an anonymous collection, and you can obtain the data by querying the database It should be noted here:
The returned parameters must be total and rows, total returns the total number of data sets, and rows returns the json format of the table
5. Display effect
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <title>@ViewBag.Title</title> @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") </head> <body> @RenderBody() @*@Scripts.Render("~/bundles/jquery")*@ @RenderSection("scripts", required: false) </body> </html>Put it in the red box in the picture above Comment out the js file and run
and find it successful! This is because the references to JS library files are in order, must first reference the JQuery library file, and then reference the plug-in js
The above is the detailed content of bootstrap table from scratch. For more information, please follow other related articles on the PHP Chinese website!

BootstrapisafreeCSSframeworkthatsimplifieswebdevelopmentbyprovidingpre-styledcomponentsandJavaScriptplugins.It'sidealforcreatingresponsive,mobile-firstwebsites,offeringaflexiblegridsystemforlayoutsandasupportivecommunityforlearningandcustomization.

Bootstrapisafree,open-sourceCSSframeworkthathelpscreateresponsive,mobile-firstwebsites.1)Itoffersagridsystemforlayoutflexibility,2)includespre-styledcomponentsforquickdesign,and3)ishighlycustomizabletoavoidgenericlooks,butrequiresunderstandingCSStoop

Bootstrap is suitable for quick construction and small projects, while React is suitable for complex and interactive applications. 1) Bootstrap provides predefined CSS and JavaScript components to simplify responsive interface development. 2) React improves performance and interactivity through component development and virtual DOM.

The main purpose of Bootstrap is to help developers quickly build responsive, mobile-first websites. Its core functions include: 1. Responsive design, which realizes layout adjustments of different devices through a grid system; 2. Predefined components, such as navigation bars and modal boxes, ensure aesthetics and cross-browser compatibility; 3. Support customization and extensions, and use Sass variables and mixins to adjust styles.

Bootstrap is better than TailwindCSS, Foundation, and Bulma because it is easy to use and quickly develop responsive websites. 1.Bootstrap provides a rich library of predefined styles and components. 2. Its CSS and JavaScript libraries support responsive design and interactive functions. 3. Suitable for rapid development, but custom styles may be more complicated.

Integrating Bootstrap in React projects can be done in two ways: 1) introduced using CDN, suitable for small projects or rapid prototyping; 2) installation using npm package manager, suitable for scenarios that require deep customization. With these methods, you can quickly build beautiful and responsive user interfaces in React.

Advantages of integrating Bootstrap into React projects include: 1) rapid development, 2) consistency and maintainability, and 3) responsive design. By directly introducing CSS files or using the React-Bootstrap library, you can use Bootstrap's components and styles efficiently in your React project.

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.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools