EasyUI行编辑,包含数据校验,combox焦点事件、级联、赋值等

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>


<t:datagrid name="tsBjjhSbxqList" title=""
actionUrl="tsBjjhSbxqController.do?datagrid&sbid=${sbid }" idField="id"
queryMode="group" checkbox="true">
<c:if test="${opt != 'ck' }">
<t:dgToolBar title="添加" icon="icon-add" funname="addRow"></t:dgToolBar>
<%-- <t:dgToolBar title="编辑" icon="icon-edit" funname="editRow"></t:dgToolBar> --%>
   <t:dgToolBar title="保存" icon="icon-save" url="tsBjjhSbxqController.do?saveRows&flag=${flag }" funname="saveData"></t:dgToolBar>
<t:dgToolBar title="取消编辑" icon="icon-undo" funname="reject"></t:dgToolBar>
<t:dgToolBar title="删除" icon="icon-remove" funname="del"></t:dgToolBar>
</c:if>
</t:datagrid>
<script type="text/javascript">
var kcxx = ""; //课程信息
var skls = ""; //授课老师
var jcxx = ""; //教材信息
var skjss = ""; //上课教室
var loaded = false;  //防止ajax再次提交
$(document).ready(function(){
//获取当前院系下的所有课程
if(!loaded){
$.ajax({
url:"tsBjjhSbxqController.do?getKcxx",
type:"post",
data:{"yxsh":'${yxsh}'},
dataType:"json",
async: false,
cache: false,
success:function(data){
if(data.success){
var d = $.parseJSON(data.jsonStr);
kcxx = d.obj;
loaded = true;
}
}
});
//根据课程名称获取授课老师
   $.ajax({
url:"tsBjjhSbxqController.do?getSkls",
type:"post",
dataType:"json",
async: false,
success:function(data){
if(data.success){
skls = data.obj;
loaded = true;
}
}
});
   //上课教室信息表
    $.ajax({
url:"tsBjjhSbxqController.do?getSkjs",
type:"post",
dataType:"json",
async: false,
success:function(data){
if(data.success){
skjss = data.obj;
loaded = true; 
}
}
});
   
//获取所有的教材信息
$.ajax({
url:"tsBjjhSbxqController.do?getJcxx",
type:"post",
dataType:"json",
async: false,
success:function(data){
if(data.success){
var d = $.parseJSON(data.jsonStr);
jcxx = d.obj;
loaded = true; 
}
}
});
}

//加载计划详情信息
loadJhxq('');
});


var ybc = '';  //已保存(行上保存按钮)
//添加行
function addRow(title,addurl,gname){
$('#'+gname).datagrid('appendRow',{sbid:"${sbid}",xqmc:"${xqmc}",bjmc:"${bjmc}", zs:'1',zks:'1',cksl:'${bjrs}',sjgmsl:'${bjrs}'});
var editIndex = $('#'+gname).datagrid('getRows').length-1;
$('#'+gname).datagrid('selectRow', editIndex).datagrid('beginEdit', editIndex);

var target_cbs = $('#'+gname).datagrid('getEditor', {index : editIndex, field:'cbs'}).target;  
target_cbs.attr("disabled", true);

var target_author = $('#'+gname).datagrid('getEditor', {index : editIndex, field:'author'}).target;  
target_author.attr("disabled", true);

var target_isbn = $('#'+gname).datagrid('getEditor', {index : editIndex, field:'isbn'}).target;  
target_isbn.attr("disabled", true);
}
//保存数据
function saveData(){
var title="";
var addurl="tsBjjhSbxqController.do?saveRows&flag=${flag }&bjdm=${bjdm}&xqdm=${xqdm}";
var gname="tsBjjhSbxqList";


if(!endEdit(gname)){
return false;
}

var rows=$('#'+gname).datagrid("getChanges","inserted");
var uprows=$('#'+gname).datagrid("getChanges","updated");
rows=rows.concat(uprows);
var flag = '0';

if(rows.length<=0){
tip("没有需要保存的数据!")
return false;
}
var result={};
for(var i=0;i<rows.length;i++){
for(var d in rows[i]){
result["demos["+i+"]."+d]=rows[i][d];
}
}
$.ajax({
url:"${pageContext.request.contextPath}/"+addurl,
type:"post",
data:result,
dataType:"json",
async:false,
cache:false,
success:function(data){
tip(data.msg);
if(data.success){
$('#'+gname).datagrid("reload");
}
}
})
ybc = 'save';
}

//结束编辑
function endEdit(gname){
var  editIndex = $('#'+gname).datagrid('getRows').length-1;
for(var i=0;i<=editIndex;i++){
if($('#'+gname).datagrid('validateRow', i)){
$('#'+gname).datagrid('endEdit', i);
}
else{
return false;
}
}
return true;
}
//编辑行
function editRow(title,addurl,gname){
var rows=$('#'+gname).datagrid("getChecked");

if(rows.length==0){
tip("请选择条目");
return false;
}
for(var i=0;i<rows.length;i++){
var index= $('#'+gname).datagrid('getRowIndex', rows[i]);
$('#'+gname).datagrid('beginEdit', index);
}
}
//update-begin--Author:张忠亮  Date:20150709 for:修正 取消编辑后再次点击录入不进入编辑状态
//取消编辑
function reject(title,addurl,gname){
$('#'+gname).datagrid('clearChecked');
$('#'+gname).datagrid('rejectChanges');
}


//删除数据
function del(gname){
var rows=$('#tsBjjhSbxqList').datagrid("getSelected");
if(rows.length >=0){
tip("请选择一条数据");
return false;

var id = rows.id;
$.ajax({
url:"tsBjjhSbxqController.do?del",
type:"post",
data:{"id":id},
dataType:"json",
success:function(data){
tip(data.msg);
if(data.success){
$('#tsBjjhSbxqList').datagrid("reload");
}
}
})
}
</script>
<script type="text/javascript">
//行编辑信息
function loadJhxq(kcmc) {
var datas = kcxx;
var lastIndex;
var $dg = $('#tsBjjhSbxqList');
var opt = '${opt}';

$dg.datagrid({
width : 600,
height : 'auto',
title : '',
singleSelect : true,
idField : 'id',
url : 'tsBjjhSbxqController.do?datagrid&sbid=${sbid }',
columns : [[{
field : 'id',
title : '编号',
width : 80,
hidden: true,
}, 
{
field : 'id',
title : '上报信息ID',
width : 80,
hidden: true,
}, 
{
field : 'xqmc',
title : '学期',
width : 80,
hidden: true,
},
{
field : 'bjmc',
title : '班级',
width : 80,
hidden: true,
},
{
field : 'skkc',
title : '授课课程',
width : 120,
editor : {
type : 'combobox',
options : {
valueField : 'KCMC',
textField : 'KCMC',
data : datas,  
required : true,  
onChange : function (data){
               //先获取到当前选中行
               //根据当前行获取,当前行的下标
               //在根据下标和要获取列的filed获取对应filed的Editor对象
               //然后在根据对应的Editor操作
var row = $dg.datagrid('getSelected');
var rowIndex = $dg.datagrid('getRowIndex', row);
var thisTarget = $dg.datagrid('getEditor', {index : rowIndex ,field : 'skkc'}).target;
 //获取输入框的值 
var value = "";
  var isExist = "Y"
  //下拉列表失去焦点事件
   $("input",thisTarget.next("span")).blur(function(){  
 //判断该课程是否存在于下拉列表中
 /* for(var i = 0 ; i < datas.length; i++) {
 if(value !=  datas[i].KCMC && value != ""){
 tip('请选择正确的授课课程');
 thisTarget.combobox('setValue','');
 isExist = "N"
 } 
 } */ 
 value = thisTarget.combobox('getValue');
 if(value != "" && value != null && typeof(value) != 'undefined'){
 $.ajax({
url:"tsBjjhSbxqController.do?getKcxx",
type:"post",
data:{"kcmc":value},
dataType:"json",
async: false,
success:function(data){
if(data.success){
var d = $.parseJSON(data.jsonStr);
if(d.obj.length == 0){
 tip('请选择正确的授课课程');
 thisTarget.combobox('setValue','');
 isExist = "N";
};
}
}
});
 }
 
 }); 
 if(isExist == "Y"){
  value = thisTarget.combobox('getValue');
//获取该课程下的授课老师
var target = $dg.datagrid('getEditor', {index : rowIndex, field:'skls'}).target;  
target.combobox('clear'); //清除原来的数据  
                               var url = 'tsBjjhSbxqController.do?getSkls&kcmc='+value;  
                               $.ajax({
                            url:url,
                            type:"post",
                            dataType:"json",
                            async: false,
                            success:function(data){
                            if(data.success){
                            var dataObj = data.obj;
                            //联动下拉列表重载  //数据 元区分大小写
                            target.combobox('loadData', dataObj);
                            }
                            }
                            });
 }
}
}
}
},{
field : 'skls',
title : '授课老师',
width : 120,
editor : {
type : 'combobox',
options : {
valueField : 'xm',
textField : 'xm',
data : skls,
required : true,
onChange : function (data){
var row = $dg.datagrid('getSelected');
var rowIndex = $dg.datagrid('getRowIndex', row);
var thisTarget = $dg.datagrid('getEditor', {index : rowIndex ,field : 'skls'}).target;
 //获取输入框的值 
var value = "";
  $("input",thisTarget.next("span")).blur(function(){ 
  value = thisTarget.combobox('getValue');
if(value != "" && value != null && typeof(value) != 'undefined'){
 $.ajax({
url:"tsBjjhSbxqController.do?getSkls",
type:"post",
data:{"xm":value},
dataType:"json",
async: false,
success:function(data){
if(data.success){
var d = $.parseJSON(data.jsonStr);
if(d.obj.length == 0){
 tip('请选择正确的授课老师');
 thisTarget.combobox('setValue','');
};
}
}
});
 } 
 });
}
}
}
},{
field : 'skjs',
title : '上课教室',
width : 120,
editor : {
type : 'combobox',
options : {
valueField : 'jsmc',
textField : 'jsmc',
data : skjss,
required : true,
onChange : function (data){
var row = $dg.datagrid('getSelected');
var rowIndex = $dg.datagrid('getRowIndex', row);
var thisTarget = $dg.datagrid('getEditor', {index : rowIndex ,field : 'skjs'}).target;
 //获取输入框的值 
var value = "";
  $("input",thisTarget.next("span")).blur(function(){ 
  value = thisTarget.combobox('getValue');
if(value != "" && value != null && typeof(value) != 'undefined'){
 $.ajax({
url:"tsBjjhSbxqController.do?getSkjs",
type:"post",
data:{"jsmc":value},
dataType:"json",
async: false,
success:function(data){
if(data.success){
var d = $.parseJSON(data.jsonStr);
if(d.obj.length == 0){
 tip('请选择正确的上课教室');
 thisTarget.combobox('setValue','');
};
}
}
});
 } 
 });
}
}
}
},{
field : 'zs',
title : '周数',
width : 70,
editor : {
type : 'numberbox',
options : {
required : true
}
}
},  {
field : 'zks',
title : '周时',
width : 70,
editor : {
type : 'numberbox',
options : {
required : true
}
}
}, {
field : 'khfs',
title : '考核方式',
width : 80,
editor : {
type : 'combobox',
options : {
valueField: 'khfsmc',
textField : 'khfsmc',
data : khfss,
required : true,
editable : false //下拉列表可选但不可编辑
}
}
}, {
field : 'jcmc',
title : '教材名称',
width : 100,
editor : {
type : 'combobox',
options : {
valueField : 'JCMC',
textField : 'JCMC',
data : jcxx,  
required : true,  
onChange : function (data){
var row = $dg.datagrid('getSelected');
var rowIndex = $dg.datagrid('getRowIndex', row);
var thisTarget = $dg.datagrid('getEditor', {index : rowIndex ,field : 'jcmc'}).target;
var value = "";
  $("input",thisTarget.next("span")).blur(function(){ 
  value = thisTarget.combobox('getValue');
if(value != "" && value != null && typeof(value) != 'undefined'){
 $.ajax({
url:"tsBjjhSbxqController.do?getJcxx",
type:"post",
data:{"jcmc":value},
dataType:"json",
async: false,
success:function(data){
if(data.success){
var d = $.parseJSON(data.jsonStr);
if(d.obj.length == 0){
 tip('请选择正确的教材名称');
 thisTarget.combobox('setValue','');
}
}
}
});
 } 
 });
  value = thisTarget.combobox('getValue');
  if(value != ''){
//获取该课程下的授课老师
$.ajax({
url:"tsBjjhSbxqController.do?getJcxx&jcmc="+value,
type:"post",
dataType:"json",
async: false,
success:function(data){
if(data.success){
var d = $.parseJSON(data.jsonStr);
if(d.obj.length > 0){
//教程ID
var target_jcid = $dg.datagrid('getEditor', {index : rowIndex, field:'jcid'}).target;
target_jcid.val(d.obj[0].ID);
//出版社
var target_cbs = $dg.datagrid('getEditor', {index : rowIndex, field:'cbs'}).target;  
target_cbs.val(d.obj[0].CBS);
target_cbs.attr("disabled", true);
//作者
var target_author = $dg.datagrid('getEditor', {index : rowIndex, field:'author'}).target;  
target_author.val(d.obj[0].AUTHOR);
target_author.attr("disabled", true);
//ISBN
var target_isbn = $dg.datagrid('getEditor', {index : rowIndex, field:'isbn'}).target;  
target_isbn.val(d.obj[0].ISBN);
target_isbn.attr("disabled", true);
} else {
var target_jcid = $dg.datagrid('getEditor', {index : rowIndex, field:'jcid'}).target;
target_jcid.val('');
//出版社
var target_cbs = $dg.datagrid('getEditor', {index : rowIndex, field:'cbs'}).target;  
target_cbs.val('');
target_cbs.attr("disabled", true);
//作者
var target_author = $dg.datagrid('getEditor', {index : rowIndex, field:'author'}).target;  
target_author.val('');
target_author.attr("disabled", true);
//ISBN
var target_isbn = $dg.datagrid('getEditor', {index : rowIndex, field:'isbn'}).target;  
target_isbn.val('');
target_isbn.attr("disabled", true);
}
}
}
});

}
}
}
}
}, {
field : 'jcid',
title : '教程ID',
width : 80,
editor : 'text',
hidden: true,
},{
field : 'cbs',
title : '出版社',
width : 100,
editor : 'text'
}, {
field : 'author',
title : '作者',
width : 80,
editor : 'text'
}, {
field : 'isbn',
title : 'ISBN',
width : 100,
editor : {
type : 'text',
options : {
disabled : true
}
}
}, {
field : 'cksl',
title : '参考数量',
width : 80
},{
field : 'sjgmsl',
title : '实际数量',
width : 80,
editor : {
type : 'numberbox',
options : {
required : true
}
}
}, {
field : 'bz',
title : '备注',
width : 250,
editor : 'text'
}, 
]],
onBeforeLoad : function () {
$(this).datagrid('clearChecked');
$(this).datagrid('rejectChanges');
},
onAfterEdit: function (index, row) {
       row.editing = false;  
       $(this).datagrid('refreshRow', index);  
},  
onClickRow : function (rowIndex) {
if(opt != 'ck'){
if (lastIndex != rowIndex) {
$dg.datagrid('endEdit', lastIndex);
$dg.datagrid('beginEdit', rowIndex);

var skkcTarget = $dg.datagrid('getEditor', {index : rowIndex ,field : 'skkc'}).target;
var skkc = skkcTarget.combobox('getValue'); 

var target = $dg.datagrid('getEditor', {index : rowIndex, field:'skls'}).target;  
//target.combobox('clear'); //清除原来的数据  
                    var url = 'tsBjjhSbxqController.do?getSkls&kcmc='+skkc;  
                    $.ajax({
                url:url,
                type:"post",
                dataType:"json",
                async: false,
                success:function(data){
                if(data.success){
                var dataObj = data.obj;
                //联动下拉列表重载 //   数据 元区分大小写
                target.combobox('loadData', dataObj);
                }
                }
                });
}
lastIndex = rowIndex;
}
}
});  
};


//定义考核方式
var khfss = [{
khfsdm: 'kc',
khfsmc: '考查'
}, {
khfsdm : 'ks',
khfsmc : '考试'
}
];






//点击dialog确定按钮,进行行内信息验证
function xxCheck(){
var gname = 'tsBjjhSbxqList';
//修改
var rows=$('#'+gname).datagrid("getChecked");

//添加
var editIndex = $('#'+gname).datagrid('getRows').length-1;
for(var i = 0 ; i < rows.length; i++) {
//授课课程
var skkc = rows[i].skkc;
if(typeof(skkc) == 'undefined'){
var skkcTarget = $('#'+gname).datagrid('getEditor', {index : editIndex ,field : 'skkc'}).target;
skkc = skkcTarget.combobox('getValue');  
if(skkc == ''){
tip('请选择授课课程!');
return false;
}
} else if(skkc == null || skkc == ''){
tip('请选择授课课程!');
return false;
}

//授课老师
var skls = rows[i].skls; 
if(typeof(skls) == 'undefined'){
var sklsTarget = $('#'+gname).datagrid('getEditor', {index : editIndex ,field : 'skls'}).target;
skls = sklsTarget.combobox('getValue');  
if(skls == ''){
tip('请选择授课老师!');
return false;
}
} else if(skls == null || skls == ''){
tip('请选择授课老师!');
return false;
}

//上课教室
var skjs = rows[i].skjs; 
if(typeof(skjs) == 'undefined'){
var skjsTarget = $('#'+gname).datagrid('getEditor', {index : editIndex ,field : 'skjs'}).target;
skjs = skjsTarget.combobox('getValue');  
if(skjs == ''){
tip('请选择上课教室!');
return false;
}
} else if(skjs == null || skjs == ''){
tip('请选择上课教室!');
return false;
}

//周数
var zs = rows[i].zs; 
if(typeof(zs) == 'undefined'){
var zsTarget = $('#'+gname).datagrid('getEditor', {index : editIndex ,field : 'zs'}).target;
zs = zsTarget.numberbox('getValue'); 
if(zs == ''){
tip('请输入周数!');
return false;
}
} else if(zs == null || zs == ''){
tip('请输入周数!');
return false;
}

//周课时
var zks = rows[i].zks; 
if(typeof(zks) == 'undefined'){
var zksTarget = $('#'+gname).datagrid('getEditor', {index : editIndex ,field : 'zks'}).target;
zks = zksTarget.numberbox('getValue');  
if(zks == ''){
tip('请输入周时!');
return false;
}
} else if(zks == null || zks == ''){
tip('请输入周时!');
return false;
}

//考核方式
var khfs = rows[i].khfs; 
if(typeof(khfs) == 'undefined'){
var khfsTarget = $('#'+gname).datagrid('getEditor', {index : editIndex ,field : 'khfs'}).target;
khfs = khfsTarget.combobox('getValue');  
if(khfs == ''){
tip('请选择考核方式!');
return false;
}
} else if(khfs == null || khfs == ''){
tip('请选择考核方式!');
return false;
}

//教材名称
var jcmc = rows[i].jcmc; 
if(typeof(jcmc) == 'undefined'){
var jcmcTarget = $('#'+gname).datagrid('getEditor', {index : editIndex ,field : 'jcmc'}).target;
jcmc = jcmcTarget.combobox('getValue');  
if(jcmc == ''){
tip('请选择教材名称!');
return false;
}
}else if(jcmc == null || jcmc == '') {
tip('请选择教材名称!');
return false;
}

//实际购买数量
var sjgmsl = rows[i].sjgmsl;  
if(typeof(sjgmsl) == 'undefined' ){
var sjgmslTarget = $('#'+gname).datagrid('getEditor', {index : editIndex ,field : 'sjgmsl'}).target;
sjgmsl = sjgmslTarget.numberbox('getValue');  
if(sjgmsl == ''){
tip('请输入实际数量!');
return false;
}
} else if(sjgmsl == null || sjgmsl == ''){
tip('请输入实际数量!');
return false;
}
}
return true; 
}
</script>
  • 1
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值