本文实例为大家分享了bootstrap table表格的使用方法,供大家参考,具体内容如下

1.进入页面,根据指定的URL加载数据(json格式)
2.加载成功,根据$table.bootstrapTable({options})显示表格样式。
感觉还是挺漂亮的哈,OK,下面贴代码解释功能。
开始之前,当然要引用js啦
<link href="~/Content/bootstrap.min.css" rel="stylesheet" /> <link href="~/Content/bootstrap-theme.min.css" rel="stylesheet" /> <link href="~/Content/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" /> <script src="~/Scripts/jquery-1.9.1.js"></script> <script src="~/Scripts/bootstrap.min.js"></script> <script src="~/Content/bootstrap-table/bootstrap-table.min.js"></script>
html代码,一是指定table要使用的工具栏,而是写一个空的table
<div class="row">
<div class="col-md-12">
<div class="btn-group" id="toobar" role="group" aria-label="...">
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-plus"></span>新增
</button>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-edit"></span>修改
</button>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-remove"></span>删除
</button>
</div>
<table id="myTable"></table>
</div>
</div>
js代码,使用("#table").bootstraptable({options})填充table
$("#myTable").bootstrapTable({
url: '/BootstrapTable/GetTestData',
method: 'get',
toolbar: '#toobar',//工具列
striped: true,//隔行换色
cache: false,//禁用缓存
pagination: true,//启动分页
sidePagination: 'client',//分页方式
pageNumber: 1,//初始化table时显示的页码
pageSize: 10,//每页条目
showFooter: false,//是否显示列脚
showPaginationSwitch: true,//是否显示 数据条数选择框
sortable: false,//排序
search: true,//启用搜索
showColumns: true,//是否显示 内容列下拉框
showRefresh: true,//显示刷新按钮
idField: 'SystemCode',//key值栏位
clickToSelect: true,//点击选中checkbox
singleSelect: true,//启用单行选中
columns: [{
checkbox: true
},
{
field: 'SystemCode',
title: '系统代码',
titleTooltip: 'young for you'
},
{
field: 'SystemDesc',
title: '系统名称'
},
{
field: 'Isvalid',
title: '是否有效'
},
{
field: 'UUser',
title: '更新人'
},
{
field: 'UDate',
title: '更新时间'
}],
onClickCell: function (field, value, row, $element) {
//alert(row.SystemDesc);
}
});
其中URL是table 数据源地址,如果table启动了分页功能,后台取数据的方法要加上limit、offset两个int类型的参数,这里把后台代码也贴一下。
public JsonResult GetTestData(int limit, int offset)
{
BugzillaModelContainer db = new BugzillaModelContainer();
List<B_SystemInfo> systemInfo = db.B_SystemInfo.ToList();
for (int i = 0; i < 20; i++)
{
B_SystemInfo tempSystem = new B_SystemInfo();
tempSystem.SystemCode = (i + 1).ToString();
tempSystem.SystemDesc = "测试系统" + (i + 1).ToString();
tempSystem.Isvalid = "Y";
tempSystem.UUser = "result_for" + (i + 1).ToString();
tempSystem.UDate = System.DateTime.Now.ToShortDateString();
systemInfo.Add(tempSystem);
}
var total = systemInfo.Count();
var rows = systemInfo.Skip(offset).Take(limit).ToList();
return Json(systemInfo, JsonRequestBehavior.AllowGet);
}
offset表示从多少条数据开始取,limit表示取多少条数据。
客户端搜索只要设置search=true即可。
服务端搜索,需要设置参数。
首先设置
("#table").bootstraptable({queryParams: oTableInit.queryParams}),//传递参数(*)
然后获取查询的参数
//得到查询的参数
oTableInit.queryParams = function (params) {
var temp = {
//这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的
limit: params.limit, //页面大小
offset: params.offset, //页码
systemcode: $("#systemcode").val(),
};
return temp;
};
通过button事件刷新table,重新获取数据源,即可。
$("#btnQuery").click(function () {
$table.bootstrapTable('refresh');
});
最后贴上全部html代码~
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link href="~/Content/bootstrap.min.css" rel="external nofollow" rel="stylesheet" />
<link href="~/Content/bootstrap-theme.min.css" rel="external nofollow" rel="stylesheet" />
<link href="~/Content/bootstrap-table/bootstrap-table.min.css" rel="external nofollow" rel="stylesheet" />
<script src="~/Scripts/jquery-1.9.1.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Content/bootstrap-table/bootstrap-table.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-8">
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="btn-group" id="toobar" role="group" aria-label="...">
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-plus"></span>新增
</button>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-edit"></span>修改
</button>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-remove"></span>删除
</button>
</div>
<table id="myTable"></table>
</div>
</div>
</div>
<script>
$(function () {
var itable = TableInit();
itable.Init();
});
var TableInit = function () {
var myTableInit = new Object();
myTableInit.Init = function () {
$("#myTable").bootstrapTable({
url: '/BootstrapTable/GetTestData',
method: 'get',
toolbar: '#toobar',//工具列
striped: true,//隔行换色
cache: false,//禁用缓存
pagination: true,//启动分页
sidePagination: 'client',//分页方式
pageNumber: 1,//初始化table时显示的页码
pageSize: 10,//每页条目
showFooter: false,//是否显示列脚
showPaginationSwitch: true,//是否显示 数据条数选择框
sortable: false,//排序
search: true,//启用搜索
showColumns: true,//是否显示 内容列下拉框
showRefresh: true,//显示刷新按钮
idField: 'SystemCode',//key值栏位
clickToSelect: true,//点击选中checkbox
singleSelect: true,//启用单行选中
columns: [{
checkbox: true
},
{
field: 'SystemCode',
title: '系统代码',
titleTooltip: 'young for you'
},
{
field: 'SystemDesc',
title: '系统名称'
},
{
field: 'Isvalid',
title: '是否有效'
},
{
field: 'UUser',
title: '更新人'
},
{
field: 'UDate',
title: '更新时间'
}],
onClickCell: function (field, value, row, $element) {
//alert(row.SystemDesc);
}
});
};
return myTableInit;
};
</script>
</body>
</html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# bootstrap
# table
# 表格
# Bootstrap table使用方法总结
# bootstrap table表格插件使用详解
# bootstrap table实现单击单元格可编辑功能
# Angularjs+bootstrap+table多选(全选)支持单击行选中实现编辑、删除功能
# bootstrap table动态加载数据示例代码
# bootstrap table sum总数量统计实现方法
# 分页
# 更新时间
# 每页
# 条数
# 栏位
# 加载
# 下拉框
# 一是
# 大家分享
# 贴上
# 要使
# 具体内容
# 服务端
# 大家多多
# 客户端
# 变量名
# 源地址
# 启动了
# label
# role
相关文章:
巅云智能建站系统:可视化拖拽+多端适配+免费模板一键生成
如何制作算命网站,怎么注册算命网站?
建站之星展会模板:智能建站与自助搭建高效解决方案
网站制作的软件有哪些,制作微信公众号除了秀米还有哪些比较好用的平台?
C++用Dijkstra(迪杰斯特拉)算法求最短路径
定制建站方案优化指南:企业官网开发与建站费用解析
建站主机选择指南:服务器配置与SEO优化实战技巧
建站主机选购指南:核心配置优化与品牌推荐方案
高端云建站费用究竟需要多少预算?
香港代理服务器配置指南:高匿IP选择、跨境加速与SEO优化技巧
香港服务器网站生成指南:免费资源整合与高速稳定配置方案
,购物网站怎么盈利呢?
网站建设制作需要多少钱费用,自己做一个网站要多少钱,模板一般多少钱?
如何在香港服务器上快速搭建免备案网站?
如何用虚拟主机快速搭建网站?详细步骤解析
建站主机助手选型指南:2025年热门推荐与高效部署技巧
如何在Golang中使用replace替换模块_指定本地或远程路径
一键制作网站软件下载安装,一键自动采集网页文档制作步骤?
国美网站制作流程,国美电器蒸汽鍋怎么用官方网站?
如何通过虚拟主机快速搭建个人网站?
香港服务器网站搭建教程-电商部署、配置优化与安全稳定指南
,南京靠谱的征婚网站?
西安大型网站制作公司,西安招聘网站最好的是哪个?
如何快速查询网站的真实建站时间?
微网站制作教程,不会写代码,不会编程,怎么样建自己的网站?
我的世界制作壁纸网站下载,手机怎么换我的世界壁纸?
如何用免费手机建站系统零基础打造专业网站?
建站之星安装失败:服务器环境不兼容?
已有域名能否直接搭建网站?
如何在云主机快速搭建网站站点?
,有什么在线背英语单词效率比较高的网站?
中山网站制作网页,中山新生登记系统登记流程?
在线教育网站制作平台,山西立德教育官网?
建站之星备案流程有哪些注意事项?
高端建站三要素:定制模板、企业官网与响应式设计优化
海南网站制作公司有哪些,海口网是哪家的?
宝塔建站后网页无法访问如何解决?
昆明网站制作哪家好,昆明公租房申请网上登录入口?
网站海报制作教学视频教程,有什么免费的高清可商用图片网站,用于海报设计?
存储型VPS适合搭建中小型网站吗?
nginx修改上传文件大小限制的方法
七夕网站制作视频,七夕大促活动怎么报名?
北京网站制作费用多少,建立一个公司网站的费用.有哪些部分,分别要多少钱?
如何通过万网虚拟主机快速搭建网站?
制作网站软件推荐手机版,如何制作属于自己的手机网站app应用?
宝塔面板创建网站无法访问?如何快速排查修复?
教程网站设计制作软件,怎么创建自己的一个网站?
高防服务器:AI智能防御DDoS攻击与数据安全保障
如何在自有机房高效搭建专业网站?
西安市网站制作公司,哪个相亲网站比较好?西安比较好的相亲网站?
*请认真填写需求信息,我们会在24小时内与您取得联系。