最近需要做一些数据表格,有同事推荐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 使用方法的更多相关文章

  1. Bootstrap Table列宽拖动的方法

    在之前做过的一个web项目中,前端表格是基于jQuery和Bootstrap Table实现的,要求能利用拖动改变列宽,现将实现的过程记录如下: 1. Bootstrap Table可拖动,需要用到它 ...

  2. bootstrap table 兼容ie8 -- refreshOptions

    今天项目使用 bootstrap table 在ie8下发现 方法 refreshOptions 报错. 经过调试监控发现错误如下: 153 行 代码 Object.getOwnPropertyNam ...

  3. Bootstrap table方法,Bootstrap table事件,配置

    调用 BootStrap Table 方法的语法: $('#table').bootstrapTable('method', parameter); 例如: $('#my_table').bootst ...

  4. ABP+AdminLTE+Bootstrap Table权限管理系统第六节--abp控制器扩展及json封装以及6种处理时间格式化的方法

    返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 一,控制器AbpController 说完了Swagger ui 我们再来说一下abp对控制器的处理和json的封 ...

  5. Bootstrap Table使用方法详解

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

  6. bootstrap Table API和一些简单使用方法

    官网: http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/ 后端分页问题:后端返回”rows”.“”total,这样才能重新赋值 ...

  7. JS组件系列——表格组件神器:bootstrap table(三:终结篇,最后的干货福利)

    前言:前面介绍了两篇关于bootstrap table的基础用法,这章我们继续来看看它比较常用的一些功能,来个终结篇吧,毛爷爷告诉我们做事要有始有终~~bootstrap table这东西要想所有功能 ...

  8. 后台系统组件:一丶bootstrap table

    http://www.cnblogs.com/landeanfen/p/4976838.html (bootstrap table) http://www.cnblogs.com/landeanfen ...

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

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

随机推荐

  1. python入门(2)python的安装

    python入门(2)python的安装 Python是跨平台的,可以运行在Windows.Mac和各种Linux/Unix系统上. 2.x还是3.x Python有两个版本,一个是2.x版,一个是3 ...

  2. [Luogu1801] 黑匣子 - Treap

    Description Black Box是一种原始的数据库.它可以储存一个整数数组,还有一个特别的变量i.最开始的时候Black Box是空的.而i等于0.这个Black Box要处理一串命令. 命 ...

  3. ORACLE数据库编程

    第一章 Oracle数据库基本概念 一.介绍 Oracle数据库系统是美国Oracle(甲骨文)公司提供的以分布式数据库为 核心的一组软件产品,是目前最流行的客户/服务器(Client/Server, ...

  4. jquery的attr()方法

    一.定义和用法 attr() 方法设置或返回被选元素的属性和值. 当该方法用于返回属性值,则返回第一个匹配元素的值. 当该方法用于设置属性值,则为匹配元素设置一个或多个属性/值对. 二.语法 返回属性 ...

  5. Spring Cloud学习笔记-004

    高可用注册中心 在微服务架构这样的分布式环境中,需要充分考虑发生故障的情况,所以在生产环境中必须对各个组件进行高可用部署,对于微服务如此,对于服务注册中心也一样.如果一直使用单节点的服务注册中心,这在 ...

  6. angular中使用echart遇到的获取容器高度异常的问题记录

    问题 在使用echart去创建图表时,发现图表只占了容器的一个角落,如图,并没有充满容器. 第一反应是容器元素的样式有问题,于是我把容器的宽高都改为px指定的(之前是百分比设定的,查询资料发现说ech ...

  7. MySQL 5.7 新特性之初始化

    1. 把二进制安装包下载放在/opt 目录下并解压 2. 创建软连接, 并添加运行环境 ln -s /usr/local/mysql /opt/mysql-5.7.18-linux-glibc2.5- ...

  8. 使用 dotnet cli 命令上传 nuget 程序包

    前言 前面写了一篇文章介绍了如何将自己的程序集打包成nuget package并上传到nuget.org,传送门.全部是通过网页端来进行操作的,现在介绍一种比较方便快捷的方法就是用dotnet cli ...

  9. [LeetCode] Prime Number of Set Bits in Binary Representation 二进制表示中的非零位个数为质数

    Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime ...

  10. 织云Lite发布:详解包管理核心能力

    本文由 织云平台团队 发布于 腾讯云云+社区 织云Lite发布 腾讯织云自动化运维体系经过10年技术积淀,维护近万个业务模块,超过20万节点.鉴于业界朋友的呼声,我们将织云的核心功能独立抽象出来,凝结 ...