jquery easyui-datagrid手动增加删除重置行
1.实现的效果图如下


2.界面:
<div region="center">
<table id="tt">
</table>
</div>
3.引入的js文件
<link rel="stylesheet" type="text/css" href="http://www.cnblogs.com/script/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="http://www.cnblogs.com/script/themes/icon.css" />
<script type="text/javascript" src="http://www.cnblogs.com/script/jquery-1.4.2.min.js" </script>
<script type="text/javascript" src="http://www.cnblogs.com/script/jquery.easyui.min.js" </script>
<script type="text/javascript" src="http://www.cnblogs.com/script/locale/easyui-lang-zh_CN.js" mce_src="script/locale/easyui-lang-zh_CN.js"></script>
4.实现的js代码:
<script type="text/javascript">
var id;
$(document).ready(function () { //初始化所在城区
var dialogParams = window.dialogArguments;
var obj = dialogParams[0];
var xmaqryPartJson = obj['xmaqryPartJson'];
$("[id^=gfzrzt_]").each(function(){
document.getElementById($(this).attr("id")).value = obj[$(this).attr("id").replace("gfzrzt_","")]
})
id = obj['id'];
initData(xmaqryPartJson)
});
function initData(xmaqJson) {
if (xmaqJson == '' || xmaqJson == undefined || xmaqJson == null) {
showTable(new Array());
} else {
var data = $.parseJSON(xmaqJson);
showTable(data);
}
}
var lastIndex = undefined;
function showTable(xmaqJson) {
$("#tt").datagrid({
idField: "id",
fitColumns: false,
title: "项目专职安全生产管理人员",
singleSelect: true,
frozenColumns: [[
{ field: 'id', checkbox: true }
]],
columns: [
[
{field: 'zrztid', align: "center", width: 0},
{field: 'gcid',hidden: true, align: "center", width: 0},
{field: 'gccode', align: "center", width: 0},
{field: 'zzid',hidden: true, align: "center", width: 0},
{field: 'zzsj', align: "center", width: 0},
{field: 'xm', title: '姓名', width: 130, sortable: true, align: 'center',required:true, editor: {type:'text'}},
{field: 'aqsckhzh', title: '安全生产考核证号', width: 150, sortable: true, align: 'center', editor: 'text'},
{field: 'lxdh', title: '联系电话', width: 100, sortable: true, align: 'center', editor: 'text'}
]
],
toolbar: [{
text: '添加',
iconCls: 'icon-add',
handler: function () {
if (endEditing()){
$('#tt').datagrid('appendRow',{row: {
id:'',zrztid:id,gcid:'',
gccode: '',
zzid: '',
zzsj: '',
xm:'',
aqsckhzh: '',
lxdh:''
}});
if($('#tt').datagrid('getRows') != undefined){
lastIndex = $('#tt').datagrid('getRows').length-1;
}
$('#tt').datagrid('selectRow', lastIndex)
.datagrid('beginEdit', lastIndex)
}
}
}, '-', {
text: '删除',
iconCls: 'icon-remove',
handler: function () {
var row = $('#tt').datagrid('getSelected');
if (row) {
var index = $('#tt').datagrid('getRowIndex', row);
$('#tt').datagrid('cancelEdit', index).datagrid('deleteRow', index);
lastIndex = undefined;
}
}
}
// ,'-', {
// text: '保存',
// iconCls: 'icon-save',
// handler: function () {
// if (endEditing()){
// $('#tt').datagrid('acceptChanges');
// }
// }
// }
, '-', {
text: '重置',
iconCls: 'icon-undo',
handler: function () {
$('#tt').datagrid('rejectChanges');
lastIndex = undefined;
}
}] ,
onClickRow: function (index){
if (lastIndex != index){
if (endEditing()){
$('#tt').datagrid('selectRow', index)
.datagrid('beginEdit', index);
lastIndex = index;
} else {
$('#tt').datagrid('selectRow', lastIndex);
}
}
}
});
$("#tt").datagrid("loadData", xmaqJson);
} function endEditing(){
if (lastIndex == undefined){return true}
if ($('#tt').datagrid('validateRow', lastIndex)){
var ed = $('#tt').datagrid('getEditor', {index:lastIndex,field:'xm'});
var xm = $(ed.target).val();
var ed1 = $('#tt').datagrid('getEditor', {index:lastIndex,field:'aqsckhzh'});
var aqsckhzh = $(ed1.target).val();
if(xm != '' && xm != undefined && aqsckhzh !='' && aqsckhzh != undefined){
$('#tt').datagrid('endEdit', lastIndex);
lastIndex = undefined;
return true;
}else{
alert("项目专职安全生产管理人员第"+(lastIndex+1)+"行【姓名】和【安全生产考核】必须填写");
return false;
}
} else {
return false;
}
}
</script>
jquery easyui-datagrid手动增加删除重置行的更多相关文章
- JQuery EasyUI DataGrid根据条件设置表格行样式(背景色)
1.javascript定义函数返回样式 <script type="text/javascript"> //根据条件设置表格行背景颜色 function setRow ...
- 扩充 jQuery EasyUI Datagrid 数据行鼠标悬停/离开事件(onMouseOver/onMouseOut)
客户需求: jQuery EasyUI Datagrid 用户列表鼠标悬停/离开数据行时显示人员头像(onMouseOver/onMouseOut) 如图所示,Datagrid 鼠标悬停/离开数据行时 ...
- 扩展 jQuery EasyUI Datagrid 数据行鼠标悬停/离开事件(onMouseOver/onMouseOut)
客户需求: jQuery EasyUI Datagrid 用户列表鼠标悬停/离开数据行时显示人员头像(onMouseOver/onMouseOut) 如图所示,Datagrid 鼠标悬停/离开数据行时 ...
- jquery easyui datagrid 获取Checked选择行(勾选行)数据
原文:jquery easyui datagrid 获取Checked选择行(勾选行)数据 getSelected:取得第一个选中行数据,如果没有选中行,则返回 null,否则返回记录. getSel ...
- JQuery easyUi datagrid 中 自定义editor作为列表操作按钮列
转自 http://blog.csdn.net/tianlincao/article/details/7494467 前言 JQuery easyUi datagrid 中 使用datagrid生 ...
- jquery easyui datagrid使用参考
jquery easyui datagrid使用参考 创建datagrid 在页面上添加一个div或table标签,然后用jquery获取这个标签,并初始化一个datagrid.代码如下: 页面上 ...
- 扩展jquery easyui datagrid编辑单元格
扩展jquery easyui datagrid编辑单元格 1.随便聊聊 这段时间由于工作上的业务需求,对jquery easyui比较感兴趣,根据比较浅薄的js知识,对jquery easyui中的 ...
- JQuery easyUi datagrid 中 editor 动态设置最大值最小值
前言 近来项目中使用到 easyui 来进行页面设计,感觉挺方便的,但是网上除了api外,其他有价值的资料比较少,故在此分享一点经验,供大家参考. 问题 JQuery easyUi datagri ...
- jQuery EasyUI DataGrid Checkbox 数据设定与取值
纯粹做个记录,以免日后忘记该怎么设定. 这一篇将会说明两种使用 jQuery EasyUI DataGrid 的 Checkbox 设定方式,以及在既有数据下将 checked 为 true 的该笔数 ...
随机推荐
- MySQL-----操作练习
一.表关系 请创建如下表,并创建相关约束 二.操作表 1.自行创建测试数据 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: select A.student_id from (select ...
- linux下的文档处理及tar命令
1.使用cat命令进行纵向合并 使用‘>’是将左边的内容覆盖到右边 使用‘>>’是将左边的内容追加到右边文档中 还可使用‘>’将不同文件进行合并 2.管道符‘|’统计行数 使用 ...
- 怎样签发SSL证书
最近在做怎样让网站有SSL,搞了一天,现在总结一下 首先要安装OPENSSL和 Java的 keytool 先用OPENSSL生成私钥和CSR openssl req -newkey rsa:2048 ...
- hihoCoder#1036 Trie图
原题地址 看了这篇博文,总算是把Trie图弄明白了 Runtime Error了无数次,一直不知道为什么,于是写了个脚本生成了一组大数据,发现果然段错误了. 调试了一下午,总算闹明白了,为什么呢? 1 ...
- CALayer之 customizing timing of an animation
customizing timing of an animation Timing is an important part of animations, and with Core Animatio ...
- nyoj_176_队花的烦恼二_201404262008
队花的烦恼二 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 ACM队队花C小+最近在X大OJ上做题,竟发现了一道做不出来的…水题!她快郁闷死了……也许是最近状态不太 ...
- C++ fill 和memset
以下内容来自www.cplusplus.com--------------------------------------------------- FILL: template <class ...
- 创建Django项目(五)——URL配置和视图
2013-08-07 20:02:10| 1.新建blog的URL文件 在blog目录下新建文件"urls.py" : # -*- coding: ...
- Network -UVa315(连通图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=sh ...
- 动态演示冒泡排序java
动态演示冒泡排序java //冒泡排序是一种简单的交换排序,基本思路,从数列左边开始扫描元素,在扫描过程中依次对相邻元素进行比较,将较大元素后移. public class NumberSort { ...