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
How to do a conditional Cell Update
12/08/2009
17:57
Avatar
Pete
Member
Members
Forum Posts: 100
Member Since:
01/09/2008
sp_UserOfflineSmall Offline

I have cells that are related in a row.  If one cell changes, then a different cell in the row should be updated.  What event should I use to capture the change to the first cell in the row so that I can update the second?  In some cases I just want to update the data in the other cell.  In other cases I may want to change the edit options (change the list of select values).

Psuedo code would be something like:

On cellValueChange(cell)

     update cell # 2 contents

I took a look at afterEditCell but it doesn't seem to trigger when the cell contents changes.  What event should I look at?

Thanks

13/08/2009
02:46
Avatar
glemarie
France
Member
Members
Forum Posts: 66
Member Since:
19/12/2008
sp_UserOfflineSmall Offline

I used afterSaveCell : afterEditCell is triggered before any modification. You could also use beforeSaveCell.

The wiki contains the order in which events are triggered

13/08/2009
10:58
Avatar
Pete
Member
Members
Forum Posts: 100
Member Since:
01/09/2008
sp_UserOfflineSmall Offline

Thanks for the wiki reference.  I need to remind myself to look there. 

That did not work.  Let me give you a bit more information, perhaps I didn't explain enough of what I am doing.

I am using jqGrid 3.4.4 and I am using inline editing.  As I change the contents of one cell (depending upon it's name) I want to change the contents of another cell.

I added the afterSaveCell like so:

    afterSaveCell:function(id,cellName,data,iRow,iCol){
        if(cellName=='code')
            setCell(id,'description','New Cell Description');
    },

I can see the afterSaveCell event is triggered as the grid is created and populated, but if I then edit the contents of the cell and click into another cell, the afterSaveCell event isn't triggered.  Really, what I want is an 'onCellChange' event that triggered whenever the cell contents change.

Thanks for your help.  Can you see any other way to do this?

14/08/2009
02:57
Avatar
glemarie
France
Member
Members
Forum Posts: 66
Member Since:
19/12/2008
sp_UserOfflineSmall Offline

Hi,

If I remember, the two events I mentionned are only triggered when the field value is modified (I use jqGrid 3.5 and the events are correctly fired). And no, I don't see any other solution... sorry 🙁

Just a point : the code you mentionned is your real code ? If it is, it seems that you should call setCell from the grid object, like $('#mygrid').setCell

14/08/2009
09:30
Avatar
Pete
Member
Members
Forum Posts: 100
Member Since:
01/09/2008
sp_UserOfflineSmall Offline

Thanks.  Bummer!  The code snippet is part of the larger instantiation of the grid object itself.  I think the code is correct but since afterSaveCell is never fired, I never had a chance to debug the code.  I ran into several issues when I used the 3.5 version so I reverted back to 3.4.4  Eventually I'll go to 3.5 but I have a deadline and don't want to spend time re-working code at this point.

So there is no way to capture an event that fires when the cell contents change in 3.4.4?  I'll have to look into it more closely.  Maybe I can modify the existing code to trigger an event when the data in the cell changes.

15/08/2009
02:53
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Check the demo. There is such example.

Regards

Tony

P.S. The first that I will do is to put alert before the if statement

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

17/08/2009
09:09
Avatar
Pete
Member
Members
Forum Posts: 100
Member Since:
01/09/2008
sp_UserOfflineSmall Offline

Can you give me a hint as to which example you are referring to?  I looked at the Load Complete example but that is triggered by all the data being loaded from the server *I think*.

What I need is an example of where the *cell* has been edited (or something close to a row by row, cell by cell edit).  If I add the following to my grid constructor:

    formatCell:function(rowid,cellname,value,irow,icol){
            alert("Format!");
    },   
    beforeEditCell:function(rowid,cellname,value,irow,icol){
            alert("Before Edit!");
    },

But these even never seem to trigger.  If I can find an event that is triggered by an individual cell being edited in an inline edit, I think I can hook up the logic I need

19/08/2009
05:14
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Where you call these event?

Also check: New in version 3.3 - > Cell Editing

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

19/08/2009
17:59
Avatar
Pete
Member
Members
Forum Posts: 100
Member Since:
01/09/2008
sp_UserOfflineSmall Offline

Well, not finding any examples, I did it this way:

$('#subUT').jqGrid({
   url: jsonURL,
   editurl: editURL,
  datatype: 'json',
   height: 250,
   colNames:['Day of the Week', 'Begin Time','Ending Time'],
  colModel:[
   {name:'dayOfWeek',index:'dayOfWeek', width:150, editable:true},
   {name:'startTime',index:'startTime', width:100, editable:true},
      {name:'endTime',index:'endTime', width:100, editable:true} 
   ], 
  rowNum:10,
  rowList:[10,20,30],
  imgpath: gridimgpath,
  sortname: 'dayOfWeek',
     onSelectRow: function(id){
        
        if(id && (id != lastsel)){
            var mySavedRow = $('#subUT').getGridParam('savedRow');
            var rownumsaved = mySavedRow.length - 1;
            if(rownumsaved >=0)
                var rowData = mySavedRow[rownumsaved];
       
            if(rowData)
                savedSubRowData = rowToString(rowData);
            $('#subUT').saveRow(lastsel,saveRowCheck,editURL,{'extras':savedSubRowData});
            $('#subUT').editRow(id,true,clockpick);
            lastsel=id;
        }
    },
    formatCell:function(rowid,cellname,value,irow,icol){
            alert('Format!');
    },
    beforeEditCell:function(rowid,cellname,value,irow,icol){
            alert('Before Edit!');
    },
  sortorder: "desc",
  jsonReader: {repeatitems: false},
  caption: "Substitute Unavailable Times"
  });

It may be the wrong way to implement it but that is what I did.  Confused

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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