bootstrap-table 实现单击单元格可编辑
来源:互联网 发布:linux查看端口被占用 编辑:程序博客网 时间:2024/05/16 11:44
要使bootstrap-table实现可编辑,需要配合使用x-editable插件。
先在页面上导入必要的css和js文件
<!DOCTYPE html><html lang="zh-CN"><head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"> <title>bootstrap-table demo</title> <!-- Bootstrap 3.3.6 --> <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"> <!-- Bootstrap table --> <link rel="stylesheet" href="bootstrap-table-1.11.0/bootstrap-table.css"> <!-- x-editable --> <link rel="stylesheet" href="x-editable/bootstrap3-editable/css/bootstrap-editable.css"></head><body> <div class="container"> <p></p> <table id="table" class="table table-bordered table-hover"> </table> </div> <!-- jQuery 2.2.0 --> <script src="jQuery-2.2.0.min.js"></script> <!-- Bootstrap 3.3.6 --> <script src="bootstrap/js/bootstrap.min.js"></script> <!-- bootstrap table --> <script src="bootstrap-table-1.11.0/bootstrap-table.js"></script> <script src="bootstrap-table-1.11.0/extensions/editable/bootstrap-table-editable.js"></script> <script src="x-editable/bootstrap3-editable/js/bootstrap-editable.js"></script> <script src="bootstrap-table-1.11.0/locale/bootstrap-table-zh-CN.min.js"></script> <script type="text/javascript"> $(function(){ $('#table').bootstrapTable({ url:'data.json', columns:[ {field: 'id',title: 'ID'}, {field: 'name',title: '名称'}, {field: 'price',title: '单价'}, {field: 'number',title: '数量', sortable:true, cellStyle:function(value,row,index) { return { "css":{ padding:'0px' } }; }, formatter:function(value,row,index){ if(value == undefined) return "0"; else return value; }, editable:{ type:'text', clear:false, validate:function(value){ if(isNaN(value)) return {newValue:0, msg:'只允许输入数字'}; else if(value<0) return {newValue:0, msg:'数量不能小于0'}; else if(value>=1000000) return {newValue:0, msg:'当前最大只能输入999999'}; }, display:function(value){ $(this).text(Number(value)); }, //onblur:'ignore', showbuttons:false, defaultValue:0, mode:'inline' } }, {field:'amount', title: '总价'} ], //height:300, idField:'id', onEditableHidden: function(field, row, $el, reason) { // 当编辑状态被隐藏时触发 if(reason === 'save') { var $td = $el.closest('tr').children(); $td.eq(-1).html((row.price*row.number).toFixed(2)); $el.closest('tr').next().find('.editable').editable('show'); //编辑状态向下一行移动 } else if(reason === 'nochange') { $el.closest('tr').next().find('.editable').editable('show'); } } }); $('#table').on( 'click', 'td:has(.editable)', function (e) { //e.preventDefault(); e.stopPropagation(); // 阻止事件的冒泡行为 $(this).find('.editable').editable('show'); // 打开被点击单元格的编辑状态 } ); }); </script></body></html>
0 1
- bootstrap-table 实现单击单元格可编辑
- GUI Table 可编辑单元格
- 单击单元格实现可编辑的表格(学号和姓名下)
- SWT的Table表格可编辑单元格
- Angularjs bootstrap table多选(全选),支持单击行选中 ,实现编辑、删除功能
- gridview 单元格单击编辑
- SWT双击table单元格可编辑、变为下拉框
- bootstrap table实现x-editable的行单元格编辑及解决数据Empty和支持多样式
- bootstrap-table 行内编辑简单实现
- bootstrap table 合并单元格
- bootstrap table 合并单元格
- bootstrap table 双击可编辑,添加、删除行
- html5 contenteditable 实现table可编辑
- table点击实现可编辑文本
- Jquery 实现可编辑的table
- 可编辑单元格ALV
- easyui 可编辑单元格
- Bootstrap可编辑表格
- spark在windows本地调试
- JDK1.8版本下载及环境变量配置
- Qt + ffmpeg播放器
- 简单crm的项目实现(第一天)
- Windows中BeautifulSoup的安装方法
- bootstrap-table 实现单击单元格可编辑
- 350. Intersection of Two Arrays II
- AngularJS动态切换样式
- JavaSE学习52:细说多线程之Thread类和Runable接口
- Servlet 单例吗?action单例吗?
- Zombie in Matrix
- yum info node报Error:No matching Packages to list yum没有对应的包信息。
- 针对无人机航拍视频中动态背景下的目标检测
- 1005. 继续(3n+1)猜想 (25)(java实现)