Forum


03:21

23/09/2010

Hello,
I'm having a weird cell editing problem. So the basic configuration is a grid with 10 columns, the first column being a hidden ID colum. The grid is in cellEdit mode with cellsubmit set to clientArray. Only two columns are editable (in this case, column indexes 5 and 6). The request from my client is to make it behave as close to Excel as possible (try to contain your shock and amazement ;).
Anyway, it's fairly straightforward. If in column 5 and they hit tab, it should save the current cell and move over to editing column 6 on the same row. If they hit enter instead of tab, then it saves the cell and moves down a row in the same column. If they are in column 6 and hit tab, then it saves the cell and moves onto editing the cell on the next row in column 5. If they hit enter, then it just moves down a row and stays in column 6. In any of those cases, hitting tab or enter will cause the current cell to be saved and then moved onto editing the appropriate cell according to the rules above.
My problem is that when in column 6, and the user hits tab, instead of saving the current cell and moving on to edit column 5 on the next row, it seems to clear the value in the current cell and moves onto the next row. It's really odd. I have narrowed the line where it screws up to be the call to editCell right after saveCell in dataEvents (in either handlers, for tab or enter). One of the other columns has to be recalculated after every cell edit. When the behavior screws up like this, the recalculated column outputs 'NaN', which would lead me to believe that there's some invalid data in the last edited cell. In the code snippet below, theGrid is a global instance of the grid that was saved upon initilization. theGrid.CurrentRowEditing and theGrid.CurrentColEditing are global numeric variables that keep track of the cell being edited. It is updated in beforeCellEdit and set to the iRow and iCol that was passed into that handler.
Any feedback that would help me in debugging this issue would be greatly appeciated! Thank you! 🙂
The code snippet is as follows:
[...the colModel...]
[...dataInit...]
[...dataEvents...]
this.dataEvents = [
{
type: "keydown",
fn: function(e) {
var key = e.charCode || e.keyCode;
switch (key) {
case 9: { // Tab
if (theGrid.CurrentColEditing == 6) {
theGrid.Instance.jqGrid("saveCell", theGrid.CurrentRowEditing, theGrid.CurrentColEditing);
theGrid.Instance.jqGrid("editCell", ++theGrid.CurrentRowEditing, --theGrid.CurrentColEditing, true);
}
break;
}
case 13: { // Enter
theGrid.Instance.jqGrid("saveCell", theGrid.CurrentRowEditing, theGrid.CurrentColEditing);
theGrid.Instance.jqGrid("editCell", (theGrid.CurrentRowEditing + 1), theGrid.CurrentColEditing, true);
break;
}
case 27: { // Escape
theGrid.Instance.jqGrid("restoreCell", theGrid.CurrentRowEditing, theGrid.CurrentColEditing);
break;
}
case 35: { // End
break;
}
case 36: { // Home
break;
}
case 37: { // Left
break;
}
case 38: { // Up
break;
}
case 39: { // Right
break;
}
case 40: { // Down
break;
}
}
}
}
];
03:24

23/09/2010

In the switch statement, within cases 9 and 13, this is the line where it causes the weird behavior:
theGrid.Instance.jqGrid("editCell", ++theGrid.CurrentRowEditing, --theGrid.CurrentColEditing, true);
If I set the last parameter to false, it doesn't screw up. However, I need it to go into edit mode when they tab-or-enter into the next cell.
06:15

23/09/2010

I figured it out 🙂 I didn't need to invoke "cellSave" in my keypress cases. Ultimately, I ended up removing dataInit and dataEvents all together, and just utilizing afterEditCell to select the input element and bind my own event handlers. It was just less code and seemed cleaner that way for the time being.
Most Users Ever Online: 715
Currently Online:
65 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66