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 的该笔数 ...
随机推荐
- <input type="button" /> 和<input type="submit" /> 的区别
<input type="button" /> 这就是一个按钮.如果你不写javascript 的话,按下去什么也不会发生.<input type="s ...
- BNUOJ 7697 Information Disturbing
Information Disturbing Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on HDU. ...
- Android渲染器Shader:LinearGradient(一)
Android渲染器Shader:LinearGradient(一) LinearGradient是Android的线性渲染器.我写5个LinearGradient渲染器渲染后的View表现结果 ...
- codevs3728 联合权值
题目描述 Description 输入描述 Input Description 输出描述 Output Description 样例输入 Sample Input 样例输出 Sample Output ...
- JQuery判断radio是否选中并获取选中值的示例代码
这篇文章主要介绍了JQuery判断radio是否选中并获取选中值的方法,代码很简单,但很实用,需要的朋友可以参考下 其他对radio操作功能,以后在添加.直接上代码,别忘记引用JQuery包 ? 1 ...
- Google Protocol Buffer 的使用(二)
一.protobuf应用场景 protobuf 在Java中的应用场景可以是序列化和反序列化,流可以通过文件或者通过网络TCP/UDP等方式传输.新建一个.proto文件 syntax = " ...
- pandas中计算总体标准差
标准差(或方差),分为 总体标准差(方差)和 样本标准差(方差). 前者分母为n,后者为n-1.后者是无偏的. pandas里的 .std() 和 .var() 都是算的无偏的. 而numpy是有偏的 ...
- 解决Spring MVC无法接收AJAX使用PUT与DELETE请求传输的内容
解决Spring MVC无法接收AJAX使用PUT与DELETE请求传输的内容 解决方案 在 Web.xml文件中 加入以下代码 <!--解决ajax Put与Del请求无法接收到传输的内容-- ...
- Python/Java程序员面试必备常用问题解析与答案
转自AI算法联盟,理解python技术问题,以及一些常见的java面试中经常遇到的问题,这些面试问题分为四类: 是什么(what) 如何做(how) 说区别/谈优势(difference) 实践操作( ...
- fastjson过滤器简单记录
fastjson过滤器,该字段可以将转化的json字段遍历,方便实用 1 /** * 通用输出json * @param object * @return json字符串 */ public Stri ...