我是否知道如何更新"设备类型"根据" Code"?例如,"设备类型"是' IPad Air'当' 1'选择"代码"。 " onClickCell"和" onEndEdit"被发现不适合我,因为他们没有触发" Code"选择,但在另一行选择。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Row Editing in DataGrid - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css"
href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../../jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
<table id="dg" class="easyui-datagrid" title="Row Editing in DataGrid"
style="width: 700px; height: auto"
data-options="
iconCls: 'icon-edit',
singleSelect: true,
method: 'get',
data: [
{codeid:'', deviceType:'', location:'', comment:'', purchaseDate:'',setupDate:'',deviceId:''},
{codeid:'', deviceType:'', location:'', comment:'', purchaseDate:'',setupDate:'',deviceId:''}
],
onClickCell: onClickCell,
onEndEdit: onEndEdit,
onAfterEdit: onAfterEdit
">
<thead>
<tr>
<th data-options="field:'codeid',width:50,
formatter:function(value,row){
return row.codeid;
},
editor:{
type:'combobox',
options:{
valueField:'codeid',
textField:'codename',
method:'get',
data: [{codeid: '1', codename: '1'}
,{codeid: '2', codename: '2'}
,{codeid: '3', codename: '3'}],
required:false
}
}">Code</th>
<th data-options="field:'deviceType',width:135,editor:'textbox'">Type of Device</th>
<th data-options="field:'location',width:150,align:'left',editor:'textbox'">Location(s)</th>
<th data-options="field:'comment',width:150,align:'left',editor:'textbox'">Comment on Condition</th>
<th data-options="field:'purchaseDate',width:100,editor:'datebox'">Purchase Date</th>
<th data-options="field:'setupDate',width:110,align:'left',editor:'datebox'">Setup Date</th>
<th data-options="field:'deivceId',hidden:true">deviceId</th>
</tr>
</thead>
</table>
<div style="height: auto" align='left'>
<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="append()"></a>
<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removeit()"></a>
<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="accept()"></a>
</div>
<script type="text/javascript">
var editIndex = undefined;
var editIndexP2 = undefined;
var editIndexP3 = undefined;
function endEditing() {
if (editIndex == undefined) {
return true;
}
if ($('#dg').datagrid('validateRow', editIndex)) {
$('#dg').datagrid('endEdit', editIndex);
editIndex = undefined;
return true;
} else {
return false;
}
}
function onClickCell(index, field, value) {
console.log('onClickCell(index, field, value)');
if (editIndex != index) {
if (endEditing()) {
$('#dg').datagrid('selectRow', index).datagrid('beginEdit', index);
var ed = $('#dg').datagrid('getEditor', {index : index, field : field});
if (ed) {
($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
}
editIndex = index;
} else {
setTimeout(function() {
$('#dg').datagrid('selectRow', editIndex);
}, 0);
}
}
}
function onEndEdit(index, row, changes) {
console.log('onEndEdit(index, row, changes), ' + row.codeid);
var ed = $(this).datagrid('getEditor', {
index : index,
field : 'codeid'
});
row.codeid = $(ed.target).combobox('getText');
alert(row.codeid);
}
function onAfterEdit(index, row, changes) {
console.log('onAfterEdit(index, row, changes)');
}
function append() {
if (endEditing()) {
$('#dg').datagrid('appendRow', {deviceId : ''});
editIndex = $('#dg').datagrid('getRows').length - 1;
$('#dg').datagrid('selectRow', editIndex).datagrid('beginEdit', editIndex);
}
}
function removeit() {
if (editIndex == undefined) {
return
}
$('#dg').datagrid('cancelEdit', editIndex).datagrid('deleteRow',
editIndex);
editIndex = undefined;
}
function accept() {
if (endEditing()) {
$('#dg').datagrid('acceptChanges');
var d = $('#dg').datagrid('getData');
document.getElementById("myTextarea").value = JSON.stringify(d);
alert(JSON.stringify(d));
}
}
function reject() {
$('#dg').datagrid('rejectChanges');
editIndex = undefined;
}
function getChanges() {
var rows = $('#dg').datagrid('getChanges');
alert(rows.length + ' rows are changed!');
}
</script>
</body>
</html>