bootstrap table 和 x-editable 使用方法
最近需要做一些数据表格,有同事推荐EasyUI,但经过比较选择了Bootstrap table,一款极为强大的表格组件,基于Bootstrap 的 jQuery 。本文还将介绍Bootstrap-editable(行内编辑功能)使用方法。
Bootstrap下载地址:http://v3.bootcss.com/getting-started/#download
Bootstrap table下载地址:https://github.com/wenzhixin/bootstrap-table
Bootstrap-editable下载地址:https://github.com/vitalets/x-editable
一、Bootstrap table
1.引入js和css文件
<script src="{% static 'jquery/jquery.min.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
<script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
<link rel="stylesheet" type="text/css" src="{% static 'bootstrap/css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'bootstrap-table-develop\dist\bootstrap-table.css' %}">
<script src="{% static 'bootstrap-table-develop\dist\bootstrap-table.js' %}"></script>
<script src="{% static 'bootstrap-table-develop\dist\locale\bootstrap-table-zh-CN.js' %}"></script>
<script>
$(function () {
$.post('/search/',{url:url}, function (data) {
$("#table").bootstrapTable('destroy'); // 销毁数据表格
$('#table').bootstrapTable({ method: 'get',
cache: false,
height: 500,
striped: true,
pagination: true,
pageSize: 20,
pageNumber:1,
pageList: [10, 20, 50, 100, 200, 500],
search: true,
showColumns: true,
showRefresh: true,
showExport: true,
exportTypes: ['csv','txt','xml'],
search: false,
clickToSelect: true,
data: data,
columns: [{
field: "productname",
title: "商品",
}, {
field: "scanweight",
title: "重量", },{
field: "standard",
title: "标品", },{
field: "status",
title: "状态",
}],
});
});
}); </script>
data:返回数据必须是json格式。
$("#table").bootstrapTable('destroy')销毁数据表格。没有这段代码的话,每次返回新的数据都不会显示,原因是有缓存。
二、bootstrap-editable
如果我们需要对表格行内进行编辑要怎么办呢,bootstrap-editable插件可以帮我们实现。
1.导入bootstrap-editable里面的js和css文件
<script src="{% static 'bootstrap-table-develop\dist\extensions\editable\bootstrap-table-editable.js' %}"></script>
<link href ="{% static 'bootstrap-editable\css\bootstrap-editable.css' %}" rel="stylesheet" />
<script src="{% static 'bootstrap-editable\js\bootstrap-editable.js' %}"></script>
2.代码
<script>
$(function () {
$.post('/search/',{url:url}, function (data) {
$("#table").bootstrapTable('destroy'); // 销毁数据表格
$('#table').bootstrapTable({
method: 'get',
cache: false,
height: 500,
striped: true,
pagination: true,
pageSize: 20,
pageNumber:1,
pageList: [10, 20, 50, 100, 200, 500],
search: true,
showColumns: true,
showRefresh: true,
showExport: true,
exportTypes: ['csv','txt','xml'],
search: false,
clickToSelect: true,
data: data,
columns: [{
field: "productname",
title: "商品",
}, {
field: "scanweight",
title: "重量",
editable:{
type: 'text',
title: 'ScanWeight',
validate: function (v) {
if (isNaN(v)) return '必须是数字';
var status = parseInt(v);
if (status < 0) return '必须是正整数';
}
}
},{
field: "standard",
title: "标品",
},{
field: "status",
title: "状态",
editable:{
type: 'text',
title: '1:正常,2:缺货',
validate: function (v) {
if (isNaN(v)) return '必须是数字';
var status = parseInt(v);
if (status <= 0 || status>2) return '必须1或者2';
}
}
}],
onEditableSave: function (field, row, oldValue, $el) {
$.ajax({
type: "post",
url: "/Edit/",
data: row,
dataType: 'JSON',
success: function (data) {
console.log(data)
},
error: function (err) {
console.log(err)
},
complete: function () {
}
});
}
});
});
});
</script>
后端处理代码就不贴出来了,用ajax和后台交互就可以。
bootstrap table 和 x-editable 使用方法的更多相关文章
- Bootstrap Table列宽拖动的方法
在之前做过的一个web项目中,前端表格是基于jQuery和Bootstrap Table实现的,要求能利用拖动改变列宽,现将实现的过程记录如下: 1. Bootstrap Table可拖动,需要用到它 ...
- bootstrap table 兼容ie8 -- refreshOptions
今天项目使用 bootstrap table 在ie8下发现 方法 refreshOptions 报错. 经过调试监控发现错误如下: 153 行 代码 Object.getOwnPropertyNam ...
- Bootstrap table方法,Bootstrap table事件,配置
调用 BootStrap Table 方法的语法: $('#table').bootstrapTable('method', parameter); 例如: $('#my_table').bootst ...
- ABP+AdminLTE+Bootstrap Table权限管理系统第六节--abp控制器扩展及json封装以及6种处理时间格式化的方法
返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 一,控制器AbpController 说完了Swagger ui 我们再来说一下abp对控制器的处理和json的封 ...
- Bootstrap Table使用方法详解
http://www.jb51.net/article/89573.htm bootstrap-table使用总结 bootstrap-table是在bootstrap-table的基础上写出来的,专 ...
- bootstrap Table API和一些简单使用方法
官网: http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/ 后端分页问题:后端返回”rows”.“”total,这样才能重新赋值 ...
- JS组件系列——表格组件神器:bootstrap table(三:终结篇,最后的干货福利)
前言:前面介绍了两篇关于bootstrap table的基础用法,这章我们继续来看看它比较常用的一些功能,来个终结篇吧,毛爷爷告诉我们做事要有始有终~~bootstrap table这东西要想所有功能 ...
- 后台系统组件:一丶bootstrap table
http://www.cnblogs.com/landeanfen/p/4976838.html (bootstrap table) http://www.cnblogs.com/landeanfen ...
- [前端插件]Bootstrap Table服务器分页与在线编辑应用总结
先看Bootstrap Table应用效果: 表格用来显示数据库中的数据,数据通过AJAX从服务器加载,同时分页功能有服务器实现,避免客户端分页,在加载大量数据时造成的用户体验不好.还可以设置查询数据 ...
随机推荐
- 新概念英语(1-39)Don't drop it!
新概念英语(1-39)Don't drop it! Where does Sam put the vase in the end ? A:What are you going to do with t ...
- 新概念英语(1-23)Which glasses?
Which glasses does the man want? A:Give me some glasses please, Jane? B:Which glasses? These glasses ...
- Spring入门(3-1)Spring的标签命名空间
1.标签命名空间声明: 2.标签命名空间使用 标签默认的命名空间是 security:,可以不用带 security:,直接写标签,如: <http <authentication-ma ...
- [机器学习Lesson3] 梯度下降算法
1. Gradient Descent(梯度下降) 梯度下降算法是很常用的算法,可以将代价函数J最小化.它不仅被用在线性回归上,也被广泛应用于机器学习领域中的众多领域. 1.1 线性回归问题应用 我们 ...
- spring3——IOC之基于XML的依赖注入(DI )
我们知道spring容器的作用是负责对象的创建和对象间关系的维护,在上一篇博客中我们讲到spring容器会先调用对象的无参构造方法创建一个空值对象,那么接下来容器就会对对象的属性进行初始化,这个初始化 ...
- CTF中常见密码题解密网站总结
0x00.综合 网站中包含大多编码的解码. http://web2hack.org/xssee/ https://www.sojson.com/ http://web.chacuo.net/ 0x01 ...
- Android自定义圆形图片工具类(CTRL+C加CTRL+V直接使用)
先贴一下工具类的代码!可直接复制粘贴 public class RoundImageView extends ImageView { private Paint mPaint; //画笔 privat ...
- *args和**kwargs
#coding=utf8 __author__ = 'Administrator' # 当函数的参数不确定时,可以使用*args和**kwargs.*args没有key值,**kwargs有key值 ...
- POJ-1328 Radar Installation--区间选点问题(贪心)
题目链接: https://vjudge.net/problem/POJ-1328 题目大意: 假设陆地的海岸线是一条无限延长的直线,海岛是一个个的点,现需要在海岸线上安装雷达,使整个雷达系统能够覆盖 ...
- Spring Cloud学习笔记-002
搭建Spring Cloud注册中心:Eureka 服务注册:在服务治理框架中,通常都会构建一个注册中心,每个服务单元向注册中心登记自己提供的服务,将主机与端口号.版本号.通信协议等一些附加信息告诉注 ...