我有一个网格可以检查网格中的重复数字。我成功实现了,但是在我的程序检查重复条形码后,我恢复了行并尝试再次编辑以让用户重新输入正确的条形码,但是这次在编辑方法上输入键事件没有触发
重现我得到的内容的步骤如下
请在此处查看代码。要查看我遇到了什么错误,请在第一行输入一个数字(第一列只能在网格中编辑)并在第二行输入相同的数字,它会给出错误提示重复条形码,所以我希望用户更改数字但它此时不启动editMethod?请帮忙
代码 :
var portalBarcodeGrid = namespace.extend(com,'com.barcodeGrid');
门户条码网格 = {
/*requestInfo : {
reOpenMode : true,
NextApplicableStep : 'SHIP_LOAN',
RequestNumber : 'PAT_10000165',
LoanTrackingInfo : [
{LocalNumber : 'LON1', LoanStatusComplete : true },
{LocalNumber : 'LON2', LoanStatusComplete : true },
{LocalNumber : 'LON3', LoanStatusComplete : true },
{LocalNumber : 'LON4', LoanStatusComplete : true },
{LocalNumber : 'LON5', LoanStatusComplete : true },
]
},*/
requestInfo : {
NextApplicableStep : 'SHIP_LOAN',
RequestNumber : 'PAT_10000165',
LoanTrackingInfo : [
]
},
requestProcessStatus : {
LoanTrackingInfo : [
//{LocalNumber : '', ProcessStatus : ''}
]
},
processStatus : {
PENDING : 'Pending',
PROCESSING : 'Processing',
PROCESSSUCCESS : 'Process Success',
PROCESSFAILED : 'Process Failed',
UNDOSUCCESS : 'Undo Success',
UNDOFAILED : 'Undo Failed'
},
initializeBarcodeGrid : function( gridSelector ) {
$(gridSelector).jqGrid({
datatype : "local",
width : 'auto',
height : 'auto',
gridview : true,
shrinkToFit : true,
colNames : [ 'Barcode', 'Status' ],
colModel : [ {name : 'LocalNumber',resizable : false,sortable : false, editoptions: { maxlength: 15 }},
{name : 'ProcessStatus',resizable : false,sortable : false},
],
onSelectRow : function(rowId, status, e) {
portalBarcodeGrid.onBarcodeGridSelectRow( gridSelector, rowId );
},
editurl: 'clientArray',
});
// apply height and width rules to parent of the grid
$(gridSelector).parents('div.ui-jqgrid-bdiv').css("max-height","120px");
$(gridSelector).parents('div.ui-jqgrid-bdiv').css("max-width","480px");
$(gridSelector).parents('div.ui-jqgrid-bdiv').css("overflow-x","hidden");
},
selectBarcodeGridRow : function ( rowId ) {
console.log(" selectBarcodeGridRow ");
var gridSelector = '#'+ portalBarcodeGrid.getGridSelectorId( rowId );
$( gridSelector ).jqGrid( "setSelection", rowId, true );
},
getGridSelectorId : function ( rowId ){
return $( '#' +rowId ).closest( 'table' ).attr( 'id' );
},
onBarcodeGridSelectRow : function ( gridSelector, rowId ) {
console.log(" onBarcodeGridSelectRow ");
var currentRowNum = rowId.split('-')[1];
var editableRowId = $( gridSelector ).find( ':input' ).parent().parent().attr( 'id' );
var editableRowNum = 0;
if(editableRowId)
editableRowNum = editableRowId.split( '-' )[ 1 ];
if( editableRowId && editableRowId != rowId ){
//portalBarcodeGrid.selectBarcodeGridRow( gridSelector, editableRowId );
$( gridSelector ).jqGrid( 'saveRow', editableRowId, '', '', '', portalBarcodeGrid.getRowData );
//portalBarcodeGrid.selectBarcodeGridRow( gridSelector, rowId );
var prevTdText = $.trim( $( '#'+editableRowId ).find( 'td:first' ).text() );
if(prevTdText.length > 0 && ++editableRowNum == currentRowNum ){
var gridDataObj = $( gridSelector ).jqGrid( 'getRowData', rowId );
if(gridDataObj && gridDataObj.ProcessStatus == portalBarcodeGrid.processStatus.PROCESSSUCCESS)
$( gridSelector ).jqGrid( 'editRow', rowId, true, portalBarcodeGrid.addRows( rowId ), '', '', '' , portalBarcodeGrid.getRowData );
}
return;
}
else{
var gridDataObj = $( gridSelector ).jqGrid( 'getRowData', rowId );
if( gridDataObj.ProcessStatus != portalBarcodeGrid.processStatus.PROCESSSUCCESS && ( portalBarcodeGrid.requestInfo.NextApplicableStep == 'SHIP_LOAN' || portalBarcodeGrid.requestInfo.NextApplicableStep == 'RECEIVE_LOAN' ) ){
portalBarcodeGrid.addEditableProperty( gridSelector, rowId );
}
else{
portalBarcodeGrid.putValueInTextBox( '#txtBarcode',gridDataObj.LocalNumber );
}
}
},
putValueInTextBox : function( selector,barcode ) {
$( selector ).val( barcode );
},
addInitialGridRecord : function ( gridSelector ) {
if( portalBarcodeGrid.requestInfo.reOpenMode == true ){
portalBarcodeGrid.createBarcodeGridRows( gridSelector, portalBarcodeGrid.requestInfo.LoanTrackingInfo);
}
else if( portalBarcodeGrid.requestInfo.NextApplicableStep == 'SHIP_LOAN' || portalBarcodeGrid.requestInfo.NextApplicableStep == 'RECEIVE_LOAN' ){
portalBarcodeGrid.createBarcodeGridEmptyRows( gridSelector,6 )
}
else if( portalBarcodeGrid.requestInfo.NextApplicableStep == 'RETURN_LOAN' || portalBarcodeGrid.requestInfo.NextApplicableStep == 'COMPLETE_LOAN' ){
portalBarcodeGrid.createBarcodeGridRows( gridSelector, portalBarcodeGrid.requestInfo.LoanTrackingInfo );
}
},
createBarcodeGridEmptyRows : function( gridSelector,noOfRows ) {
var gridId = gridSelector.split('#')[1];
for( var i = 0; i < noOfRows; i++ ){
var obj = {};
obj.LocalNumber = '';
if( i == 0 )
obj.ProcessStatus = portalBarcodeGrid.processStatus.PENDING;
else
obj.Status = '';
portalBarcodeGrid.requestProcessStatus.LoanTrackingInfo.push( obj );
$( gridSelector ).jqGrid( 'addRowData', gridId+'_tr-'+(i+1), obj );
}
// select first row of the grid
var rowId = $( gridSelector ).getDataIDs()[0];
portalBarcodeGrid.selectBarcodeGridRow( rowId );
},
createBarcodeGridRows : function( gridSelector, loanTrackingInfo ) {
var loanTrackingCount = loanTrackingInfo == undefined || loanTrackingInfo.length == 0 ? 1 : loanTrackingInfo.length;
var numOfRows = Math.ceil((loanTrackingCount + 1) / 6 ) * 6;
var lastDataRowId = 0;
portalBarcodeGrid.createBarcodeGridEmptyRows(gridSelector, numOfRows);
var arrayRef = loanTrackingInfo;
var gridId = gridSelector.split('#')[1];
var getArrDataId = $( gridSelector ).jqGrid( 'getDataIDs' );
for( var i = 0; i < arrayRef.length; i++ ){
$( gridSelector ).jqGrid( 'setCell', getArrDataId[i], 'LocalNumber', arrayRef[i].LocalNumber );
if(arrayRef[i].LoanStatusComplete)
$( gridSelector ).jqGrid( 'setCell', getArrDataId[i], 'ProcessStatus', portalBarcodeGrid.processStatus.PROCESSSUCCESS );
else
$( gridSelector ).jqGrid( 'setCell', getArrDataId[i], 'ProcessStatus', portalBarcodeGrid.processStatus.PENDING );
lastDataRowId = getArrDataId[i];
}
if(portalBarcodeGrid.requestInfo.reOpenMode){
portalBarcodeGrid.addPendingMsg( gridSelector, gridId, lastDataRowId );
}
},
addPendingMsg : function( gridSelector, gridIdToAppendToRowId, lastDataRowId ) {
var pendingRowNum = lastDataRowId.split( '-' )[ 1 ];
portalBarcodeGrid.addPendingRow( gridSelector, gridIdToAppendToRowId+'_tr-'+(++pendingRowNum) );
},
addPendingRow : function ( gridSelector,rowId ) {
portalBarcodeGrid.selectBarcodeGridRow( rowId );
$( gridSelector ).jqGrid( 'setCell', rowId, 'ProcessStatus', portalBarcodeGrid.processStatus.PENDING );
},
addEditableProperty : function( gridSelector,rowId ){
console.log(" addEditableProperty ");
var prevTdText = $.trim( $( '#'+rowId ).prev('tr').find('td:first').text() );
var rowNum = rowId.split( '-' )[ 1 ];
if( rowNum == 1 ) {
$(gridSelector).jqGrid( 'setColProp', 'LocalNumber', { editable : true } );
$( gridSelector ).jqGrid( 'editRow', rowId, true, '', '', '', '', portalBarcodeGrid.getRowData );
}
if( rowNum > 1 ) {
if( prevTdText.length < 1 ){
$( gridSelector ).jqGrid( 'setColProp', 'LocalNumber', { editable : false } );
}
else{
$( gridSelector ).jqGrid( 'setColProp', 'LocalNumber', { editable : true } );
$( gridSelector ).jqGrid( 'editRow', rowId, true, portalBarcodeGrid.addRows( rowId ), '', '', '' , portalBarcodeGrid.getRowData );
}
}
},
addRows : function( rowId ) {
console.log(" addRows ");
var gridSelector = '#'+ portalBarcodeGrid.getGridSelectorId( rowId );
var gridId = gridSelector.split( '#' )[ 1 ];
var lastrowid = $( gridSelector ).jqGrid( 'getDataIDs' ).pop();
var prevTD = $.trim( $( '#'+rowId ).prev( 'tr' ).find( 'td:first' ).text());
if ( rowId == lastrowid ) {
if( prevTD.length > 1 ) {
var rowId = lastrowid.split('-')[1];
for ( var i = 0; i < 6; i++) {
var obj = {};
var addRow = $( gridSelector ).jqGrid( 'addRowData', gridId+'_tr-'+(++rowId),obj );
}
}
}
},
getRowData : function( rowId,result ) {
console.log(" getRowData ");
var gridSelector = '#'+ portalBarcodeGrid.getGridSelectorId( rowId );
var gridDataObj = $( gridSelector ).jqGrid( 'getRowData', rowId );
if( $.trim(gridDataObj.LocalNumber) != 0 ){
var barcodeDuplicate = portalBarcodeGrid.getDuplicateBarcode( gridSelector, rowId, gridDataObj );
if( !barcodeDuplicate ) {
$( gridSelector ).jqGrid( 'setCell', rowId, 'ProcessStatus', portalBarcodeGrid.processStatus.PROCESSSUCCESS );
var rowNum = rowId.split('-')[1];
var nextTrId = $( '#'+rowId ).next( 'tr' ).attr( 'id' );
//get the next row in grid and put focus onto it
portalBarcodeGrid.selectBarcodeGridRow( nextTrId );
}
else {
$( '#'+rowId ).find( ':input' ).select();
$(gridSelector).jqGrid( 'restoreRow', rowId ,true );
portalBarcodeGrid.selectBarcodeGridRow( rowId );
}
}
else{
//$('#divError').text("Please enter a Barcode");
$( gridSelector ).jqGrid( 'restoreRow', rowId, true );
}
},
getDuplicateBarcode : function ( gridSelector, rowId) {
console.log(" getDuplicateBarcode ");
var barcodeDuplicate = false ;
var currentRowData = $( gridSelector ).jqGrid( 'getRowData', rowId );
var gridRows = $( gridSelector ).find( 'tr' );
for( var i = 0; i < gridRows.length; i++){
gridRowId = $ (gridRows [i]).attr( 'id' );
if ( currentRowData.LocalNumber == $( gridRows[i] ).find( 'td:first' ).text() && rowId != gridRowId ) {
$('#divError').text("Duplicate Barcode");
barcodeDuplicate = true;
}
}
return barcodeDuplicate;
},
};