<script type=‘text/javascript‘>
var editIndex = undefined;
$(function() {
$(‘#tb1‘).datagrid({
url:‘CourseTeachersSave.aspx?opt=GetDatagridData&xnxq=‘+$(‘#hiddenXnxq‘).val()+‘&synj=‘+$(‘#hiddenSynj‘).val()+‘&bh=‘+$(‘#hiddenBh‘).val(),
width:$(‘#tb1‘).parent().width(),
height:$(‘#tb1‘).parent().height()*0.85,
fitColumns:false,
columns:[[
{field:‘mkdm‘,hidden:true},
{field:‘zwmc‘,title:‘科目‘,width:100,align:‘center‘},
{field:‘zgh‘,title:‘任课教师‘,width:300,align:‘center‘,
formatter:function(value,row) {return row.xm},
editor:{
type:‘combobox‘,
options:{
valueField:‘zgh‘,
textField:‘xm‘,
url:‘CourseTeachersSave.aspx?opt=GetRkjsData‘,
method:‘post‘,
multiple:true,
onSelect:function(record){
if(record.zgh==‘‘) {
var ed=$(‘#tb1‘).datagrid(‘getEditor‘, {index:editIndex,field:‘zgh‘}); //最重要的是得到当前编辑行的index
$(ed.target).combobox(‘setText‘,‘‘);
$(ed.target).combobox(‘setValue‘,‘‘);
}
}
}
}
}
]],
method:‘post‘,
onClickRow: onClickRow
});
$(‘#btnqx‘).click(function() { parent.$(‘#add‘).window(‘close‘); });
$("#btnsave").click(function () {
$(‘#form‘).submit();
});
$(‘#form‘).form({
url: ‘CourseTeachersSave.aspx?opt=save‘,
onSubmit: function () {
if ($(this).form(‘validate‘)) {
var rows=$(‘#tb1‘).datagrid(‘getRows‘);
for(var i=0;i<rows.length;i++){
var ed=$(‘#tb1‘).datagrid(‘getEditor‘, {index:i,field:‘zgh‘});
if(ed!=null)
{
rows[i][‘xm‘]=$(ed.target).combobox(‘getText‘);
}
}
$(‘#tb1‘).datagrid(‘acceptChanges‘);
$(‘#hiddenStr‘).val(JSON.stringify($(‘#tb1‘).datagrid(‘getRows‘)));
LoadMsg("view");
return true;
} else {
return false;
}
},
success: function (data) {
LoadMsg(‘hidden‘);
data = jQuery.parseJSON(data);
if(data.isok) {
$.messager.alert(‘提示‘,data.msg,‘info‘,function() { parent.$(‘#add‘).window(‘close‘); }
)}
else{ $.messager.alert(‘提示‘,data.msg,‘info‘);}
}
});
});
function endEditing(){
if (editIndex == undefined){return true}
if ($(‘#tb1‘).datagrid(‘validateRow‘, editIndex)){
var ed = $(‘#tb1‘).datagrid(‘getEditor‘, {index:editIndex,field:‘zgh‘});
$(‘#tb1‘).datagrid(‘endEdit‘, editIndex);
editIndex = undefined;
return true;
} else {
return false;
}
}
function onClickRow(index){
if (editIndex != index){
if (endEditing()){
$(‘#tb1‘).datagrid(‘selectRow‘, index)
.datagrid(‘beginEdit‘, index);
editIndex = index;
} else {
$(‘#tb1‘).datagrid(‘selectRow‘, editIndex);
}
}
}
</script>