jqgrid编辑模式-在jqgrid内部焦点未更改时不设置数据

jqgrid编辑模式-在jqgrid内部焦点未更改时不设置数据,jqgrid,Jqgrid,我在编辑jqgrid单元格时遇到了一个奇怪的问题 我得到了一个保存按钮,从网格中抓取更改后的单元格值,并将其发布到服务器进行保存 当我编辑单元格并将焦点移动到网格表上的任何其他位置,然后单击“保存”按钮时,单元格值被正确传递 但是,如果我编辑单元格并直接单击save按钮而不更改网格表内的焦点,则会丢失已更改的数据 我正在使用$(“#vehicleListTable”).getChangedCells('all');从网格中获取所有编辑的行 我试图捕获事件“beforeSubmitCell、a

我在编辑jqgrid单元格时遇到了一个奇怪的问题

  • 我得到了一个保存按钮,从网格中抓取更改后的单元格值,并将其发布到服务器进行保存
  • 当我编辑单元格并将焦点移动到网格表上的任何其他位置,然后单击“保存”按钮时,单元格值被正确传递
  • 但是,如果我编辑单元格并直接单击save按钮而不更改网格表内的焦点,则会丢失已更改的数据
  • 我正在使用$(“#vehicleListTable”).getChangedCells('all');从网格中获取所有编辑的行
我试图捕获事件“beforeSubmitCell、afterEditCell、beforeSaveCell、afterSaveCell、afterSaveCell”,以查看当我完成编辑单元格并将焦点移动到保存按钮时是否调用了它,但发现没有调用任何事件。当我更改单元格并将焦点移动到网格本身时,会调用它们

有人能帮我吗? 下面是我如何创建jggrid表的片段

function initTable() {
            var vehTypesStr = "all:All;C:Car or Light Commercial;T:Heavy Commercial;M:Motorcycle;B:Boat;H:Caravan;R:Relocatable;A:Trailer";
            var stockTypesStr = "all:All;N:New;U:Used";
            var priceStatusTypesStr = "all:All;1:Over priced;-1:Under Priced;0:Neutral priced";
            jQuery("#vehicleListTable").jqGrid({                    
                url:'fetch-vehicle-list-json.action?q=2', 
                datatype: "json", 
                colNames:[                      
                    'Exception',
                    'Stock Number',
                    'Stock Type',
                    'Vehicle Type',
                    'Make',
                    'Model',
                    'Year',
                    'Drive Away Price',
                    'Price (unqualified)',
                    'Body Style',
                    'Exterior Base Colour',
                    'Odometer',
                    'Image Count',
                    'Price Status',
                    'Edited Online',
                    'Added Online'], 
                colModel:[  
                    {name:'exception',index:'exception',width:55,sortable:false,formatter:exceptionImagesFormatter,search:false},
                    {name:'stockNum',index:'stockNum',width:90},
                    {name:'vehicleNewUsedType',index:'vehicleNewUsedType',width:70,stype: 'select',searchoptions:{ sopt:['eq'], value: stockTypesStr}},
                    {name:'vehicleType',index:'vehicleType',width:120,stype: 'select',searchoptions:{ sopt:['eq'], value: vehTypesStr}},
                    {name:'make',index:'make',width:90},
                    {name:'model',index:'model',width:90},
                    {name:'year',index:'year',width:60,align:"right",search:false},
                    {name:'driveAwayPrice',index:'driveAwayPrice',width:90,align:'right',formatter:'currency',formatoptions:{thousandsSeparator:',',decimalPlaces:2,prefix:'$ ',defaulValue:''},search:false,editable:false,editrules:{number:true}},
                    {name:'egcPrice',index:'egcPrice',width:90,align:"right",formatter:'currency',formatoptions:{thousandsSeparator:",",decimalPlaces:2,prefix:"$ ",defaulValue:""},search:false},
                    {name:'bodyStyle',index:'bodyStyle',width:70},
                    {name:'exteriorColour',index:'exteriorColour',width:100,editable:false},
                    {name:'odometer',index:'odometer',width:70,search:false},
                    {name:'photoCount',index:'photoCount',width:80,align:"right",search:false},
                    {name:'priceStatus',index:'priceStatus',width:80,formatter:priceStatusImagesFormatter,stype: 'select',searchoptions:{ sopt:['eq'], value: priceStatusTypesStr }},
                    {name:'editedOnline',index:'lastModified',width:80,search:false,hidden:true},
                    {name:'addedOnline',index:'created',width:80,search:false,hidden:true}
                ],
                rowNum:20,
                scroll:1, 
                gridview: true,
                pager: '#vehicleListPager',
                sortname: "<s:property value="vehicleSearch.sortByField"/>",
                <s:if test="vehicleSearch.sortAscending">
                    sortorder:"asc",
                </s:if>
                <s:if test="!vehicleSearch.sortAscending">
                    sortorder:"desc",
                </s:if>
                viewrecords: true,
                recreateForm: true,
                recreateFilter: true,
                caption:"<s:property value="dealer.name"/>",
                multiselect: true,
                width: "40%",
                height: "250",                                      
                onSelectRow: handleTableOnSelect,                 
                beforeSelectRow: handleTableBeforeSelectRow,
                //afterInsertRow: handleTableAfterInsertRow,   
                onSelectAll: handleTableOnSelectAll,   
                loadComplete: handleTableLoadComplete,
                beforeSubmitCell: getEdittedCellData,
                afterEditCell  : getEdittedCellData,
                beforeSaveCell : getEdittedCellData,
                afterSaveCell  : getEdittedCellData,
                afterSaveCell  : getEdittedCellData       
            });
        }
函数initTable(){
var vehTypesStr=“全部:全部;C:汽车或轻型商用车;T:重型商用车;M:摩托车;B:船;H:商队;R:可重新定位;A:拖车”;
var stockTypesStr=“全部:全部;N:新;U:已使用”;
var priceStatusTypesStr=“全部:全部;1:定价过高;-1:定价过低;0:中性定价”;
jQuery(#vehicleListTable”).jqGrid({
url:'fetch-vehicle-list-json.action?q=2',
数据类型:“json”,
colNames:[
“例外情况”,
“股票编号”,
“股票类型”,
‘车辆类型’,
“制造”,
“模型”,
“年”,
“赶走价格”,
“价格(不合格)”,
“身体风格”,
“车身底色”,
“里程表”,
“图像计数”,
"价格状况",,
“在线编辑”,
“在线添加”],
colModel:[
{name:'exception',index:'exception',width:55,sortable:false,formatter:exceptionImagesFormatter,search:false},
{名称:'stockNum',索引:'stockNum',宽度:90},
{名称:'vehicleNewUsedType',索引:'vehicleNewUsedType',宽度:70,样式:'select',搜索选项:{sopt:['eq'],值:stockTypesStr},
{名称:'vehicleType',索引:'vehicleType',宽度:120,样式:'select',搜索选项:{sopt:['eq'],值:vehTypesStr},
{名称:'make',索引:'make',宽度:90},
{名称:'model',索引:'model',宽度:90},
{名称:'year',索引:'year',宽度:60,对齐:“right”,搜索:false},
{name:'driveAwayPrice',index:'driveAwayPrice',width:90,align:'right',formatter:'currency',formattoptions:{thousandsSeparator:',',decimalPlaces:2,前缀:'$',defaulValue:'},搜索:false,可编辑:false,编辑规则:{number:true},
{name:'egcPrice',index:'egcPrice',width:90,align:'right',格式化程序:'currency',格式化选项:{thousandsSeparator:“,”,decimalPlaces:2,前缀:“$”,默认值:},搜索:false},
{名称:'bodyStyle',索引:'bodyStyle',宽度:70},
{名称:'ExteriorColor',索引:'ExteriorColor',宽度:100,可编辑:false},
{名称:“里程表”,索引:“里程表”,宽度:70,搜索:false},
{名称:'photoCount',索引:'photoCount',宽度:80,对齐:“右”,搜索:false},
{名称:'priceStatus',索引:'priceStatus',宽度:80,格式化程序:priceStatusImagesFormatter,stype:'select',搜索选项:{sopt:['eq'],值:priceStatusTypesStr},
{name:'editedOnline',index:'lastModified',width:80,search:false,hidden:true},
{名称:'addedOnline',索引:'created',宽度:80,搜索:false,隐藏:true}
],
rowNum:20,
卷轴:1,
gridview:没错,
寻呼机:“#车辆列表寻呼机”,
sortname:“”,
分拣员:“asc”,
巫师:“描述”,
viewrecords:是的,
再现形式:正确,
重新创建筛选器:true,
标题:“,
多选:对,
宽度:“40%”,
高度:“250”,
OnSetRow:handleTableOnSelect,
beforeSelectRow:handleTableBeforeSelectRow,
//afterInsertRow:handleTableAfterInsertRow,
onSelectAll:handleTableOnSelectAll,
loadComplete:handleTableLoadComplete,
beforeSubmitCell:getEdittedCellData,
afterEditCell:getEdittedCellData,
beforeSaveCell:getEdittedCellData,
afterSaveCell:getEdittedCellData,
afterSaveCell:getEdittedCellData
});
}
谢谢
Sudha

我遇到了同样的问题-单元格仍处于编辑模式,GetChangedCells方法无法获取值,因为它尚未被网格“保存”。为此,请执行以下步骤-

声明两个变量以存储正在编辑的单元格的当前行和列

var saverow;
var savecol;
使用afterEditCell单元格编辑事件将当前行和列存储到新变量中。这是在jqGrid初始化选项中完成的

afterEditCell: function (id, name, val, IRow, ICol) {
     saverow = IRow;
     savecol = ICol;
}
在Save按钮的click处理程序中,确定是否有处于编辑模式的单元格,然后在jqGrid上调用saveCell方法。传入单元格的行和列值。这将存储该值。
还调用jqGrid上的editCell方法,传入
// if a cell is currently in edit mode, then we need to save it and exit edit mode
if (saverow != null && savecol != null) {
    $("#vehicleListTable").jqGrid('saveCell', saverow, savecol, true);
    $("#vehicleListTable").jqGrid('editCell', saverow, savecol, false);
    saverow = null;
    savecol = null;
}