AJAX从后台传数据,解决下拉框数值只显示Value不显示Text
function hasChanges() {
//gridUPPEquiStartStopLGPop为可编辑表格的id
changeRows = $.getGridChangesRows('gridUPPEquiStartStopLGPop');
return changeRows.hasChanges;
}
function saveChanges() {
//直接调用可编辑表格中保存事件的方法
savePTMatattributeInitLine();
}
var editIndex = undefined;
function initDataGridUPPEquiStartStopLGPop() {
var DATES = $('#DATES').datebox('getValue'); //开始时间
var DATEE = $('#DATEE').datebox('getValue'); //结束时间
$('#gridUPPEquiStartStopLGPop').datagrid({
fit: true,
fitColumns: false,
nowrap: true,
striped: true,
collapsible: true,
remoteSort: false,
singleSelect: true,
pagination: true,
rownumbers: true,
idField: 'ID',
pageSize: 20,
pageList: [20, 40, 60, 80],
url: '../ashx/JK/GYJYZLWH3PopHandler.ashx?action=query&DATES=' + DATES + '&DATEE=' + DATEE,
frozenColumns: [[
{ field: 'ID', title: 'ID', width: 80, hidden: true },
]],
columns: [[
{ field: 'EQUIPNO', title: '产线', width: 130,
formatter: function (value) {
switch (value) {
case "Q101": return "1#生产线"; break;
case "Q102": return "2#生产线"; break;
}
}
},
{ field: 'MTRLNO', title: '物料', width: 180, formatter: function (value, row, index) {
return row.MaterialDes;
},
editor: {
type: 'combobox',
options: {
valueField: 'MaterialID',
textField: 'MaterialDes',
method: 'get',
url: '../ashx/JK/GYJYZLWH3PopHandler.ashx?action=classci',
editable: false,
panelHeight: 200
}
}
},
{ field: 'FORMID', title: '传送代号', width: 180 },
{ field: 'INPUTCODE', title: '输入代码', width: 180 },
{ field: 'PROCESSCODE', title: '工序代码', width: 180 },
{ field: 'DATE', title: '日期', width: 180,
formatter: function (value) {
var date = new Date(value);
var y = date.getFullYear();
var m = date.getMonth() + 1;
var d = date.getDate();
return y + '-' + m + '-' + d;
}
},
{ field: 'datetime', title: '时间', width: 180 }
]],
onClickRow: onClickRow
});
};
/*** 结束编辑[gridUPPEquiStartStopLGPop行编辑]***/
function endEditingPTMatattributeInitLine() {
if (editIndex == undefined) { return true }
if ($('#gridUPPEquiStartStopLGPop').datagrid('validateRow', editIndex)) {
//ed的if语句 解决文字和ID可能不显示不对应的问题,直接赋值给conbobox
var ed = $('#gridUPPEquiStartStopLGPop').datagrid('getEditor', { index: editIndex, field: 'MTRLNO' }); //editIndex编辑时记录下的行号
if (ed != null) {
var MTRLNO = $(ed.target).combobox('getText');
// var MaterialID = $(ed.target).combobox('getValue');
$('#gridUPPEquiStartStopLGPop').datagrid('getRows')[editIndex]['MaterialDes'] = MTRLNO;
// $('#gridUPPEquiStartStopLGPop').datagrid('getRows')[editIndex]['MaterialID'] = MaterialID;
}
//编辑行中带下拉框的,要加上赋值
$('#gridUPPEquiStartStopLGPop').datagrid('endEdit', editIndex);
editIndex = undefined;
return true;
} else {
return false;
}
}
/***单击行事件[gridUPPEquiStartStopLGPop行编辑]***/
function onClickRow(index, row) {
var isEndEdit = endEditingPTMatattributeInitLine();
if (editIndex != index) {
if (isEndEdit) {
$('#gridUPPEquiStartStopLGPop').datagrid('selectRow', index)
.datagrid('beginEdit', index);
editIndex = index;
} else {
$('#gridUPPEquiStartStopLGPop').datagrid('selectRow', editIndex);
}
}
}
/***保存事件[PTMatattributeInit行编辑]***/
function savePTMatattributeInitLine() {
if (endEditingPTMatattributeInitLine()) {
var rows = $('#gridUPPEquiStartStopLGPop').datagrid('getRows');
changeRows = $.getGridChangesRows('gridUPPEquiStartStopLGPop');
if (changeRows.hasChanges) {
$.post('../ashx/JK/GYJYZLWH3PopHandler.ashx?action=save', { changeRows: JSON.stringify(changeRows) },
function (jsonResult) {
$.dealAjaxResult(jsonResult, function (jsonResult) {
$.show_warning_inframe(jsonResult.Msg, 'success');
$('#gridUPPEquiStartStopLGPop').datagrid('acceptChanges');
$('#gridUPPEquiStartStopLGPop').datagrid('reload').datagrid('clearSelections');
//保存成功后,也可以刷新页面(需要修改grid名称):
//$("#gridPTMatattributeInitPop").datagrid("reload");
})
});
}
}
initDataGridUPPEquiStartStopLGPop();
}