Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Weird cell editing behavior
18/07/2012
03:21
Avatar
metaGlass
Member
Members
Forum Posts: 6
Member Since:
23/09/2010
sp_UserOfflineSmall Offline

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...]

{ name: 'UnitsPerBox', index: 'UnitsPerBox', width: AppOptions.theGridColW[7], editable: false }, { name: 'Shipment2', index: 'Shipment2', width: AppOptions.theGridColW[6], editable: true, editoptions: { dataInit: this.dataInit, dataEvents: this.dataEvents } }, { name: 'Shipment1', index: 'Shipment1', width: AppOptions.theGridColW[5], editable: true, editoptions: { dataInit: this.dataInit, dataEvents: this.dataEvents } },{ name: 'Suggested', index: 'Suggested', width: AppOptions.theGridColW[4], editable: false }

[...dataInit...]

this.dataInit = function(elem) { $(elem).focus(function() { this.select(); }); };

[...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;

}

}

}

}

];

18/07/2012
03:22
Avatar
metaGlass
Member
Members
Forum Posts: 6
Member Since:
23/09/2010
sp_UserOfflineSmall Offline

Sorry about the bad code formatting and lack of indentation.  Let me know if it's a problem and I'll see if I can some how post something that's easier to read and figure out.  Also, there are any questions about the code snippets, please feel free to ask.

18/07/2012
03:24
Avatar
metaGlass
Member
Members
Forum Posts: 6
Member Since:
23/09/2010
sp_UserOfflineSmall Offline

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.

18/07/2012
06:15
Avatar
metaGlass
Member
Members
Forum Posts: 6
Member Since:
23/09/2010
sp_UserOfflineSmall Offline

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.

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information