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 ...
- 【52ABP实战教程】0.1-- Devops如何用VSTS持续集成到Github仓库!
工欲善其事,必先利其器.在开始正式的教程之前我们先来聊聊准备工作. 管理工具会VSTS. 代码管理会用GITHUB. 服务器会用Azure. 所有的东西都是利用现有服务.不会说自己从虚拟机开始玩.我们 ...
- python tornado TCPserver异步协程实例
项目所用知识点 tornado socket tcpserver 协程 异步 tornado tcpserver源码抛析 在tornado的tcpserver文件中,实现了TCPServer这个类,他 ...
- 从Mybatis源码理解jdk动态代理默认调用invoke方法
一.背景最近在工作之余,把开mybatis的源码看了下,决定自己手写个简单版的.实现核心的功能即可.写完之后,执行了一下,正巧在mybatis对Mapper接口的动态代理这个核心代码这边发现一个问题. ...
- python的单元测试
单元测试实际上就是一些"断言"(assert)代码 断言就是判断一个函数或对象的一个方法所产生的结果是否符合你期望的那个结果. python中assert断言是声明布尔值为真的判定 ...
- CWMP开源代码研究番外篇——博通方案
声明:本篇文章来自于某公司Cable Modem产品的文档资料,源码来自于博通公司,只提供参考(为保护产权,本人没有源码). 前文曾提到会写一篇关于博通的tr069,那么福利来了.福利,福利,福利,重 ...
- iOS 私有API调用
最近自己在做一个小程序,想实现一个一键设置手机壁纸的功能.但在iOS公开的API里找不到相关的方法,只能从私有API入手. 网上有不少教程,不过都不是很详细.从google和https://stack ...
- pyqt4 写动画不能播放问题集合
最近在学习动画,真的真的是血泪史,百度基本是0资源,各种在谷歌外国大佬的英文中躺过一个一个血坑....... 这是随便写的一个动画功能调试窗口..... 问题现象: 点击食灵,没反应,写的动画不能生成 ...
- Shell自学之运算符和echo(W3C)
上面理论知识,最下面有我做的测试的例子: 10.Shell运算符 expr是一款表达式计算工具,使用它能完成表达式的求值操作 例:val=`expr 2 + 2`;echo "${val}& ...
- mybatis学习二
Mybatis缓存1:缓存的概念 当用户频繁查询某些固定 的数据时,第一次将这些数据从数据库查询出来,保存在缓存中(内存,高速磁盘)中 当下次用户再次查询这些数据时,不用再通过数据库查询, ...