最近需要做一些数据表格,有同事推荐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. linux centos6.8 下安装mysql 步骤

    安装环境:vmware12.centos6.8.centos中配置阿里云数据元 1.下载mysql 运行: sudo yum -y install mysql-server 如果下载失败,可以卸载重新 ...

  2. 从微软MVP到女儿开学--2017前半年小结

    2017年转眼就到了9月,原本在年初定的计划基本泡汤了. 看书啊减肥啊出教程啊,都被因为各种事物给缠身而没有完成. 1号带女儿去报名的时候,听到老师说"家长们请到这边来集合"的时候 ...

  3. Excel 日期截取(函数)

    需求:时间段截取,去掉年月日,保留时分. 实现函数:    =TEXT(A2,"HH:MM")&"-"&TEXT(B2,"HH:MM& ...

  4. 在Linux的Terminal中显示文本文件特定行的内容

    假设要操纵的文本文件的文件名是 textFile现在想做的事情是在不以编辑模式打开文件的情况下在终端直接提取并输出指定文本文件的指定行的内容 在终端提取指定文本文件的指定行的内容 Tool Comma ...

  5. 前端学习之jquery

    前端学习之jquery 1.   什么是jQuery对象? jQuery对象就是通过jQuery包装DOM对象后产生的对象.jQuery对象是jQuery独有的.如果一个对象是jQuery对象,那么它 ...

  6. MySQL集合操作类型

    SQL语言包含3个集合操作符(union.intersect.expect)以执行各种集合操作. 此外,每个集合操作符可以有两种修饰符:一个表是包含重复项,另一个表是去除重复项(但不一定时所有的重复项 ...

  7. [JetBrains注册] 利用教育邮箱注册pycharm,idea等产品教程。

    我们在使用JetBrains的一些产品时,大多使用网上的一些key去注册或者pojie的,但是由于提供这些key的服务器并不能保证稳定可用,所以可能一段时间我们使用的ide又需要重新pojie. 这里 ...

  8. [LeetCode] Design Log Storage System 设计日志存储系统

    You are given several logs that each log contains a unique id and timestamp. Timestamp is a string t ...

  9. 【Matplotlib-01】Python 绘图库 Matplotlib 入门教程

    环境: Windows10 python3.6.4 numpy1.14.1 matplotlib2.1.2 工具:Cmder 目录: 1.线性图 2.散点图 3.饼状图 4.条形图 5.直方图 例1: ...

  10. Ubuntu重装mysql错误解决

    新搭建的服务器,先在Ubuntu上安装mariadb,后来由于很多权限问题,决定安装Mysql,在卸载过程中由于未卸载干净,导致mysql重装过程中出现了很多问题. Reading package l ...