jqGrid SetCell 和 SaveCell 在关闭模态对话框后将单元格清空
jqGrid SetCell and SaveCell blanking out the cell after closing a modal dialog
我有一个单元格可编辑的jqgrid,其中的列的编辑类型为"按钮"。 单击单元格时,将显示该按钮。 单击该按钮时,将显示一个模式对话框,允许用户从网格中选择值。 这一切都工作正常。
当用户从网格中选取值后单击模态对话框上的"确定"按钮时,我想使用用户选择的值设置单元格值并保存单元格。
单元格不是设置和保存单元格值,而是空白。 不知道为什么。
以下是相关的 jqGrid/模态对话框代码:
// global variables
base.selectedCode = null;
base.liaGridSelectedId = null;
base.liaGridSelectedICol = null;
base.liaGridSelectedIRow = null;
$("#liaGrid").jqGrid({
datatype: "local",
data: base.liaGridData,
cellEdit: true,
cellsubmit: 'clientArray',
height: 140,
colNames: ['ID', 'Class Code', 'State', 'Location Type'],
colModel: [
{ name: 'id', index: 'id', width: 90, sorttype: "int", editable: false, hidden: true },
{ name: 'ClassCode', index: 'ClassCode', width: 90, sortable: false, editable: true, edittype: "button",
editoptions: {
dataEvents: [{
type: 'click',
fn: function (e) {
e.preventDefault();
var rowid = $('#liaGrid').jqGrid('getGridParam', 'selrow');
base.liaGridSelectedId = parseInt(rowid);
$('#class-dialog').dialog('option', { width: 100, height: 200, position: 'center', title: 'Pick a Class' });
$('#class-dialog').dialog('open');
return true;
}
}]
}
},
{ name: 'LocationType', index: 'LocationType', width: 90, sortable: false, editable: true, edittype: "select", editoptions: { value: "0:;1:Rural;2:Suburban;3:Urban"} }
],
caption: "Liability Model",
beforeEditCell: function (rowid, cellname, value, iRow, iCol) {
base.liaGridSelectedICol = iCol;
base.liaGridSelectedIRow = iRow;
}
});
var infoDialog = $('#class-dialog').dialog({
autoOpen: false,
modal: true,
show: 'fade',
hide: 'fade',
resizable: true,
buttons: {
"Ok": function () {
if (base.selectedCode != null) {
$("#liaGrid").jqGrid('setCell', base.liaGridSelectedId, 'ClassCode', base.selectedCode);
$("#liaGrid").jqGrid('saveCell', base.liaGridSelectedIRow, base.liaGridSelectedICol);
$(this).dialog("close");
}
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
如上所示,我正在尝试使用 jqGrid('setCell') 和 jqGrid('saveCell') 来更新和保存单元格的内容。 不知道为什么这不能成功。
我让它工作,以防有人遇到类似的问题。 我不得不将 afterSaveCell 处理程序添加到网格中:
afterSaveCell: function (rowid, name, val, iRow, iCol) {
if (base.liaGridSelectedICol == 1) {
$("#liaGrid").jqGrid('setRowData', rowid, { ClassCode: base.selectedCode });
}
}
仅供参考 - base.selectedCode 是在模态中设置的。
奇怪的是,这仅在调用setCell和saveCell方法后才有效。 如果没有在单元级别设置和保存这些不成功的调用,则不会调用上述处理程序。
如果有人有更合适的方法来解决这个问题,我想听听。
谢谢
相关文章:
- 使用jQuery只返回选中复选框后的第一个表单元格值
- jQuery根据相关复选框选择求和单元格
- 如何使用 JavaScript 从单元格中选择第二个输入框
- jQuery表 - 如何根据选中的复选框在单元格中写入文本
- 如何获取嵌入在单元格中的文本框的值
- ExtJS 4.1 - 编辑单元格时消失的选定内容(组合框编辑器)
- 高图热图:单击按钮或复选框时选择所有单元格
- 创建带有“将值放入选定单元格”复选框的边栏
- 将单元格内容更改为输入框
- 如何引用表单元格中任意给定行的一组复选框
- 通过单击引导表单元格选中复选框
- 在客户端的编辑模式下,在同一单元格网格视图中选中复选框时禁用文本框
- 剑道网格:如何在与Angular一起使用时从组合框单元格模板中获取所选项目
- 避免单击两次以开始编辑Backgrid中的布尔(复选框)单元格
- 将 dojo 工具提示对话框添加到每个表格单元格
- jqGrid SetCell 和 SaveCell 在关闭模态对话框后将单元格清空
- 打开一个模式对话框,其中包含单击表格单元格时的动态数据
- 从成员表单元格中打开模式对话框
- ExtJs - Javascript -网格中的组合框(单元格编辑插件)-网格/窗口后面的下拉列表
- 获取具有值为jquery的复选框单元格的html内容