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_Related Related Topics sp_TopicIcon
jqGrid - id is being retained
31/05/2013
23:42
Avatar
steve_o
Member
Members
Forum Posts: 10
Member Since:
02/05/2013
sp_UserOfflineSmall Offline

I'm working with a jqGrid that displays data returned from a SQL query.  It has 4 columns, the last column contains 2 submit buttons which will allow the user to re-send an item, or to cancel their action.  When loaded, the grid loads with the buttons displayed in it, but they are disabled.  When the user selects a row, that action enables the buttons on that row only.

I created a beforeSelectRow event in which I look at lastSel (set to -1 outside the jqGrid) & compare it to the rowid.  if rowID !== lastSel, I then check to see if lastSel = -1 & return true from the beforeSelectRow event.  If lastSel <> -1 and lastSel <> rowID, then I return false ("locking" the grid from selecting another row).  I only return True if lastSel = -1 (first pass thru) or if lasSel = rowID.  

What was happening was that if I loaded the grid & didn't do the beforeSelectRow, a user could click on any number of rows & if they clicked the re-send submit button, it would re-send the last item however many times they clicked on other rows in the grid.  Clicking the re-send button on the selected row takes a couple fields from the selected row & passes them on to a function that makes an AJAX POST to add that item to a SQL table.  It then resets the selection, disables the re-send/cancel buttons in the grid and exits.  

I have the .click event functions for the re-send/cancel buttons inside the onSelectRow event. 

What I've noticed is that if I click on rows other than the initially selected one is that the click event gets called for the submit buttons multiple times.  

The desired behavior is to display the grid, and allow the user to select a row (enabling the display of the re-send/cancel buttons), keeping the user tied to that row until either the re-send or cancel button is clicked, and to then perform the appropriate actions, refreshing the grid at the end.  

The process performs as desired if the user selects a row, then clicks either cancel/re-send, and it executes the code only once.  For whatever reason, other clicks on rows other than the selected one will make it execute the re-send/cancel functions numerous times.

I'll be glad to post any additional code I have that would be helpful.  

this is the colNames & colModel portion of the grid.

colNames: ["Destination", "Message Text", "Send Time","Message Action"],

colModel:[

{name:"Destination",index:"Destination",width:col1width,align:"left", xmlmap:"Rowset>Row>Destination",sortable:false},

{name:"MessageText",index:"MessageText",width:col2width,align:"left",xmlmap:"Rowset>Row>MessageText",sortable:false},

{name:"SendTime",index:"SendTime",width:col3width,align:"center",formatter:"date",formatoptions: {"srcformat":"ISO8601Long", "newformat":"Y-m-d H:i:s"},xmlmap:"Rowset>Row>SendTime",sortable:false},

{name: "msgAct",

width: col4width,

align: "center",

formatter: function() {

return "<input name='resendMsg' style='height:25px;' type='submit' value='Re-Send' disabled='disabled' />" +

"<input name='cancelMsg' style='height:25px;' type='submit' value='Cancel' disabled='disabled' />"

}}

],

Here is the onSelectRow:

onSelectRow: function(id) {

var tr = $(this).jqGrid("getInd",id,true);

var gridRow = $(this).jqGrid("getRowData",id);

var srow = $(this).jqGrid("getGridParam","selrow");

// disable all resendMsg & cancelMsg buttons in the grid

$(this).find("input[name=resendMsg]").attr("disabled","disabled");

$(this).find("input[name=cancelMsg]").attr("disabled", "disabled");

// now enable the buttons for the current row only

$(tr).find("input[name=resendMsg]").removeAttr("disabled");

$(tr).find("input[name=cancelMsg]").removeAttr("disabled");

// catch the Cancel button click

$(tr).find("input[name=cancelMsg]").click(function() {

// disable all resendMsg & cancelMsg buttons in the grid

$(this).find("input[name=resendMsg]").attr("disabled","disabled");

$(this).find("input[name=cancelMsg]").attr("disabled", "disabled");

$("#myGrid").resetSelection(id);

//ReloadGrid();

lastSel = -1;

$("#myGrid").trigger("reloadGrid");

});

// catch the Re-Send button click

$(tr).find("input[name=resendMsg]").click(function() {

ReSendMessage(gridRow.Destination, gridRow.MessageText);

$("#myGrid").resetSelection(id);

// disable all resendMsg & cancelMsg buttons in the grid

$(this).find("input[name=resendMsg]").attr("disabled","disabled");

$(this).find("input[name=cancelMsg]").attr("disabled", "disabled");

});

},

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
54 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