最近需要做一些数据表格,有同事推荐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. GIT入门笔记(20)- git 开发提交代码过程梳理

    git开发提交流程新项目开发,可以直接往master上提交老项目维护,可以在分支上修改提交,多次add和commit之后,也可以用pull合并主干和本地master,解决冲突后再push 1.检出代码 ...

  2. React中路由传参及接收参数的方式

    注意:  路由表改变后要重启服务      方式 一:          通过params         1.路由表中                     <Route path=' /s ...

  3. NHibernate从入门到精通系列(2)——NHibernate环境与结构体系

    内容摘要 NHibernate的开发环境 NHibernate的结构体系 NHibernate的配置 一.NHibernate的开发环境 NHibernate的英文官方网站为:http://nhfor ...

  4. leetcode算法:Island Perimeter

    You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen ...

  5. 表单提交中的input、button、submit的区别

    1.input[type=submit] 我们直接来看例子: 代码如下: <form> <input name="name"> <input type ...

  6. 记录项目中用的laypage分页代码

    最终才觉得,好记性不如烂笔头,毕竟已经不是刚毕业时候的巅峰了,精力有所下降,很多时候记不住东西. 参考url:http://www.layui.com/laypage/ 直接上代码了 <scri ...

  7. POJ2398【判断点在直线哪一侧+二分查找区间】

    题意:同POJ2318 #include<algorithm> #include<cstdio> #include<cstdlib> #include<cst ...

  8. window7下配置python2.7+tornado3.3开发环境

    发现之前写太繁琐..这里分享下同学的方法 1,安装 Python 2.7.x 版本地址:https://www.python.org/downloads/release/python-278/2,安装 ...

  9. JavaEE EL & JSTL 学习笔记

    1. EL表达式(特别重要)

  10. javascript 函数的4种调用方式与 this(上下文)的指向

    前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! javascript中作用域链和this(上下文)的指向是很容易混淆的,简单的说就是: 作用域链取决于函数 ...