Bootstrap table 是一款基于 Bootstrap 的 jQuery 表格插件,功能比较完备,能够实现数据异步获取,编辑,排序等一系列功能。
官网https://bootstrap-table.com
中文https://www.bootstrap-table.com.cn

前端代码

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>BootStrap Table使用</title>
@*1、Jquery组件引用*@
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> @*2、bootstrap组件引用*@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script> @*3、bootstrap table组件以及中文包的引用*@
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.css">
<script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.15.3/dist/locale/bootstrap-table-zh-CN.min.js"></script>
@*4、页面Js文件的引用*@
<script src="~/Scripts/table/Home/Index.js"></script>
</head>
<body>
<div class="panel-body" style="padding-bottom:0px;">
<div class="panel panel-default">
<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" id="btn_query" class="btn btn-primary">查询</button>
</div>
</div>
</form>
</div>
</div> <div id="toolbar" class="btn-group">
<button id="btn_add" type="button" class="btn btn-success">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
</button>
<button id="btn_edit" type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
</button>
<button id="btn_delete" type="button" class="btn btn-danger">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
</button>
</div>
<table id="tb_departments"></table>
</div>
</body>
</html>

js代码

$(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 () {
$('#tb_departments').bootstrapTable({
url: '/Admin/news/getlist1', //请求后台的URL(*)
method: 'get', //请求方式(*)
dataType: 'json',
toolbar: '#toolbar', //工具按钮用哪个容器
theadClasses:'.thead-light',
striped: true, //是否显示行间隔色
cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
pagination: true, //是否显示分页(*)
showPaginationSwitch: false, //是否显示分页数
sortable: false, //是否启用排序
sortName: "title", //是否启用排序
sortOrder: "desc", //排序方式
queryParams: oTableInit.queryParams,//传递参数(*)
queryParamsType: '', //如果要在oTableInit.queryParams方法获取pageNumber和pageSize的值,需要将此值设置为空字符串(*)
sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
pageNumber:1, //初始化加载第一页,默认第一页
pageSize: 10, //每页的记录行数(*)
pageList: [10, 25, 50, 100], //可供选择的每页的行数(*)
search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
strictSearch: true,
showColumns: true, //是否显示所有的列
showRefresh: true, //是否显示刷新按钮
minimumCountColumns: 2, //最少允许的列数
clickToSelect: true, //是否启用点击选中行
singleSelect: false, //是否单选模式
height: $(window).height() - 200, //table总高,如果没有设置height属性,表格自动根据记录条数觉得表格高度
uniqueId: "ID", //每一行的唯一标识,一般为主键列
showToggle: false, //是否显示详细视图和列表视图的切换按钮
cardView: false, //是否显示详细视图
detailView: false, //是否显示父子表
paginationPreText: "上一页",
paginationNextText: "下一页",
columns: [{
checkbox: true
}, {
field: 'title',
title: '新闻名称'
}, {
field: 'cons',
title: '新闻内容'
}, {
field: 'pic',
title: '新闻图片'
}, {
field: 'classID',
title: '分类',
align: 'center'
}, {
field: 'times',
title: '时间'
},]
});
}; //得到查询的参数
oTableInit.queryParams = function (params) {
// 特别说明:
//这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的
     // 如果queryParamsType=limit,params包含{limit, offset, search, sort, order}
     // 如果queryParamsType!=limit,params包含{pageSize, pageNumber, searchText, sortName, sortOrder}
var temp = {
pageSize: params.pageSize, //页面大小
pageNumber: params.pageNumber, //页码
departmentname: $("#txt_search_departmentname").val(),
statu: $("#txt_search_statu").val()
};
return temp;
};
return oTableInit;
}; var ButtonInit = function () {
var oInit = new Object();
var postdata = {}; oInit.Init = function () {
$("#btn_add").click(function () {
alert("add")
}); $("#btn_edit").click(function () {
var arrselections = $("#tb_departments").bootstrapTable('getSelections');
if (arrselections.length > 1) {
alert('只能选择一行进行编辑'); return;
}
if (arrselections.length <= 0) {
alert('请选择有效数据');
return;
}
alert("edit")
//$("#myModalLabel").text("编辑");
//$("#txt_departmentname").val(arrselections[0].DEPARTMENT_NAME);
//$("#txt_parentdepartment").val(arrselections[0].PARENT_ID);
//$("#txt_departmentlevel").val(arrselections[0].DEPARTMENT_LEVEL);
//$("#txt_statu").val(arrselections[0].STATUS); //postdata.DEPARTMENT_ID = arrselections[0].DEPARTMENT_ID;
//$('#myModal').modal();
}); $("#btn_delete").click(function () {
var arrselections = $("#tb_departments").bootstrapTable('getSelections');
if (arrselections.length <= 0) {
alert('请选择有效数据');
return;
} Ewin.confirm({ message: "确认要删除选择的数据吗?" }).on(function (e) {
if (!e) {
return;
}
$.ajax({
type: "post",
url: "/Home/Delete",
data: { "": JSON.stringify(arrselections) },
success: function (data, status) {
if (status == "success") {
toastr.success('提交数据成功');
$("#tb_departments").bootstrapTable('refresh');
}
},
error: function () {
toastr.error('Error');
},
complete: function () { } });
});
}); $("#btn_submit").click(function () {
//postdata.DEPARTMENT_NAME = $("#txt_departmentname").val();
//postdata.PARENT_ID = $("#txt_parentdepartment").val();
//postdata.DEPARTMENT_LEVEL = $("#txt_departmentlevel").val();
//postdata.STATUS = $("#txt_statu").val();
//$.ajax({
// type: "post",
// url: "/Home/GetEdit",
// data: { "": JSON.stringify(postdata) },
// success: function (data, status) {
// if (status == "success") {
// toastr.success('提交数据成功');
// $("#tb_departments").bootstrapTable('refresh');
// }
// },
// error: function () {
// toastr.error('Error');
// },
// complete: function () { // } //});
}); $("#btn_query").click(function () {
$("#tb_departments").bootstrapTable('refresh');
});
}; return oInit;
};

接口代码

public JsonResult getlist1(int pageSize, int pageNumber, string departmentname, string statu)
{ var total = ;
var list=bllNews.FindPageList(pageNumber, pageSize, out total, x=>x.passed=, false, x => x.ID).ToList(); return Json(new { total = total, rows = list }, JsonRequestBehavior.AllowGet);
}

还可以实现无限极树形网格,需要用到插件jquery-treegrid

官方演示https://www.bootstrap-table.com.cn/examples/extensions/treegrid/

表格插件BootStrap-Table使用教程的更多相关文章

  1. 好用的自适应表格插件-bootstrap table (支持固定表头)

    最近工作中找到了一款十分好用的表格插件,不但支持分页,样式,搜索,事件等等表格插件常有的功能外,最主要的就是他自带的冻结表头功能,让开发制作表格十分容易,不过网上大多都是英文文档,第一次使用会比较麻烦 ...

  2. 轻量级表格插件Bootstrap Table。拥有强大的支持固定表头、单/复选、排序、分页、搜索及自定义表头等功能。

    Bootstrap Table是轻量级的和功能丰富的以表格的形式显示的数据,支持单选,复选框,排序,分页,显示/隐藏列,固定标题滚动表,响应式设计,Ajax加载JSON数据,点击排序的列,卡片视图等. ...

  3. 【转载】BootStrap表格组件bootstrap table详解

    (转载,来源“脚本之家”,作者不详) 一.Bootstrap Table的引入 关于Bootstrap Table的引入,一般来说还是两种方法: 1.直接下载源码,添加到项目里面来.由于Bootstr ...

  4. [前端插件]Bootstrap Table服务器分页与在线编辑应用总结

    先看Bootstrap Table应用效果: 表格用来显示数据库中的数据,数据通过AJAX从服务器加载,同时分页功能有服务器实现,避免客户端分页,在加载大量数据时造成的用户体验不好.还可以设置查询数据 ...

  5. Bootstrap表格组件 Bootstrap Table

    Bootstrap Table是Bootstrap的一个组件 Bootstrap Table Demo:http://issues.wenzhixin.net.cn/bootstrap-table/i ...

  6. [译]MVC网站教程(四):MVC4网站中集成jqGrid表格插件(系列完结)

    目录 1.   介绍 2.   软件环境 3.   在运行示例代码之前(源代码 + 示例登陆帐号) 4.         jqGrid和AJAX 5.         GridSettings 6.  ...

  7. Bootstrap Table使用方法详解

    http://www.jb51.net/article/89573.htm bootstrap-table使用总结 bootstrap-table是在bootstrap-table的基础上写出来的,专 ...

  8. 使用bootstrap table 插件固定表头时 表头与表格内容无法对齐

    在使用bootstrap table开发后台管理系统,表格利用bootstrap-table插件来实现,使用bootstrap-table过程中,会出现表头错位的情况 表头对不齐效果: 解决的方法: ...

  9. [转]手把手教你--Bootstrap Table表格插件及数据导出(可导出Excel2003及Exce2007)

    原文地址:https://blog.csdn.net/javayoucome/article/details/80081771 1.介绍 Bootstrap Table介绍见官网:http://boo ...

  10. bootstrap table + spring + springmvc + mybatis 实现从前端到后端的表格分页

    1.使用准备 前台需要的资源文件,主要有Bootstrap3相关css.js以及bootstrap Table相关css.js: <-- 样式 --> <link rel=" ...

随机推荐

  1. 用欧拉计划学习Rust编程(第13~16题)

    最近想学习Libra数字货币的MOVE语言,发现它是用Rust编写的,所以先补一下Rust的基础知识.学习了一段时间,发现Rust的学习曲线非常陡峭,不过仍有快速入门的办法. 学习任何一项技能最怕没有 ...

  2. Flink及Storm、Spark主流流框架比较

    转自:http://www.sohu.com/a/142553677_804130 引言 随着大数据时代的来临,大数据产品层出不穷.我们最近也对一款业内非常火的大数据产品 - Apache Flink ...

  3. 【More Effective C++ 条款1】仔细区别pointers和references

    1)操作符的差别 指针使用"*"和"->"操作符,而引用使用"."操作符 2)初始化的差别 有空指针,但是没有空引用,和const对象 ...

  4. Guarded Suspension设计模式

    Guarded Suspension 设计模式可以保证,当线程在访问某个对象时,发现条件不满足,就挂起等待条件满足时再次访问 public class GuardedSuspensionQueue { ...

  5. 关于预装操作系统的ThinkPad的分区建议

    Think的个人电脑产品大部分预装有正版操作系统,当前新产品出厂时默认都是一个大分区“C”和一个恢复分区“Q”,很多用户都会要求客服人员提供分区服务,在这里我简单说一下关于分区的几点注意事项望各位参考 ...

  6. SublimeText3安装Markdown插件

    由于Webstrom对md文件的预览效果并不理想(与实际网页编译效果差别较大),所以我又改用Sublime进行本地编辑,下面介绍一下怎么搭建环境. 插件安装 整套环境我们就需要两个插件:Markdow ...

  7. 【05】Jenkins:用户权限管理

    写在前面的话 在一个企业研发部门内部,可能存在多个运维人员,而这些运维人员往往负责不同的项目,但是有可能他们用的又是同一个 Jenkins 的不同用户.那么我们就希望实现一个需求,能够不同的用户登录 ...

  8. StringBuilder删除最后的字符

    stringbuilder碰到拼接XXx:XXX:这样的字符的时候,往往需要删除最后一个字符,通过remove(起始索引,向右移除的个数)可以实现. StringBuilder sb = new St ...

  9. Macro的写法 `( , ,@ )

    另外的注意点: 1.  同名符号的 “变量捕捉” (varible capture) 解决方式:  with-gensym 生成几个unique name-s, 然后将它们各自绑定上参数值 2. 多次 ...

  10. JAVA WEB面试总结

    本文目录: 1. 什么是cookie 2. 什么是session 3.什么是Servlet,Servlet生命周期方法 4.JSP隐含对象 5.JSP的四个域对象的作用范围 6.转发和重定向的区别 7 ...