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
Form editing add row, use '0' instead of '_empty'
19/02/2010
04:55
Avatar
jackysee
Member
Members
Forum Posts: 24
Member Since:
22/03/2009
sp_UserOfflineSmall Offline

In form editing's add row, a hidden input of "id" with value "_empty" is added.
Can it be changed to other value such as '0'?
Or can this hidden input be removed?

19/02/2010
05:11
Avatar
jackysee
Member
Members
Forum Posts: 24
Member Since:
22/03/2009
sp_UserOfflineSmall Offline

I found that I can alter the value by using

onclickSubmit: function(params){return {id:'0'}; }

Is it the proper way?

19/02/2010
12:04
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hi, jackysee!

If you want to send to server id=0 instead of id=_empty, I'll recomend you use serializeEditData. As input serializeEditData receive data, which jqQuery plan to send. You can construct another data based on input data and return it. Using serializeEditData you don't modify any internal jqGrid data, so you have no side effects compares with any kind of data modification inside of onclickSubmit.

Best regards
Oleg

22/02/2010
06:09
Avatar
jackysee
Member
Members
Forum Posts: 24
Member Since:
22/03/2009
sp_UserOfflineSmall Offline

I found that there is a side effect either I use onclickSubmit or serializeEditData. In the settings, I have closeAfterAdd: true, but the dialog does not close after add. The code is like: 

clearAfterAdd: true,
closeAfterAdd: true, 
url: '/remote.rpc?acton=add',
serializeEditData: function(data){ data.id = 0; return $.param(data);} //dialog not close after add

But strangely if I do not modify the 'data' object, the dialog can be closed successfully! i.e.

clearAfterAdd: true, 
closeAfterAdd: true, 
url: '/remote.rpc?acton=add',
serializeEditData: function(data){ return $.param(data);} //dialog close after add

This is really strange. Any workaround on this?

22/02/2010
06:29
Avatar
jackysee
Member
Members
Forum Posts: 24
Member Since:
22/03/2009
sp_UserOfflineSmall Offline

Digging into the source code found that in postIt(), it has something like:

// the action is add
if(postdata.id=="_empty" ) { 

which occurs after serializeEditData, so I changed it to

// the action is add
if(postdata.oper=="add" ) {  

and closeAfterAdd works as expected.  Any other impact if I apply this change?

22/02/2010
13:02
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hi!

First of all about serializeEditData(). If you look inside of postIt() you can see

$.ajax( $.extend({
                        url:gurl,
                        type: rp_ge.mtype,
                        data: $.isFunction(rp_ge.serializeEditData) ? rp_ge.serializeEditData(postdata) :  postdata,
                        complete:function(data,Status){

So if you don't modify postdata inside of your serializeEditData implementation, but make a copy (a clone) of all data instead, makes modification of the copy of postdata, and then return the copy, you receive NO side effects.

By the way, to make a copy of data, which has no subobjects you can do following

    var destObj = {};
    for (prop in srcObj)
            destObj[prop] = srcObj[prop];

Probably exist a nice version to produce a clone of data, but this one works.

Problem with "closeAfterAdd: true", which you describe, is an old bug inside of jqGrid. I had the problem also. But if you set both "closeAfterAdd: true" and "closeAfterEdit: true" everything will work. In all my project I use either both closeAfterAdd and closeAfterEdit as true or both as false, so I have no real problem. But to fix the problem, place it in the forum for bugs.

Best regards
Oleg

22/02/2010
19:49
Avatar
jackysee
Member
Members
Forum Posts: 24
Member Since:
22/03/2009
sp_UserOfflineSmall Offline

Thx, I've done it by:

serializeEditData: function(data){
    return $.param($.extend({}, data, {id:0}));
}
Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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