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
Added row's ID for refresh
28/02/2011
06:39
Avatar
Steffan
Member
Members
Forum Posts: 50
Member Since:
18/08/2008
sp_UserOfflineSmall Offline

Is there some kind of call back or something that I misssed where I pass some sort of response with the ID of the newly added row back to the browser so that if its edited after being added and the browser not refreshed I don't get an error? I know I can use the reloadAfterSubmit:true but it seems there has to be a better way to do it. I looked through the examples and didn't see it.

add row -> server -> add record -> return new id to browser -> browser updates table with new row ID. 

Suggestions?

Thanks,
Steffan 

28/02/2011
08:39
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Just now mention, that in the previous question with JSON data you used "userid" instead of "id". Do you used jsonReader:{id:'userid'} parameter? I updated http://www.ok-soft-gmbh.com/jq.....2-json.htm.

You should verity in IE Developer Tools or in Firebug which ids has <tr> elements and which hes new added row. The correct response from the server on "add" operation should be the id of the new row. Is it so in your grid?

Best regards
Oleg 

28/02/2011
15:26
Avatar
Steffan
Member
Members
Forum Posts: 50
Member Since:
18/08/2008
sp_UserOfflineSmall Offline

Using trial and error I found that if I wanted to use "userid" I'd have to change the parameters in my grid constructor. I've changed my code on the backend to just use whatever your plugin sends. I have all that working fine. My question is what do I need to have the server send back to the client? Currently, I have the server sending back the id of the newly created record. For example id:1234 etc. So, what do I need to do on the client (browser) side to grab the new ID and insert it into the table? Will your jsonReader example do that?

Thanks,
Steffan 

28/02/2011
15:33
Avatar
Steffan
Member
Members
Forum Posts: 50
Member Since:
18/08/2008
sp_UserOfflineSmall Offline

This is my current constructor:

$("#navgrid").jqGrid({

url:appendSession("/async/users.lasso?x=1"),

datatype: "json",

hidegrid: false,

colNames:["User ID","First Name","Last Name","Email","Password","Groups","Notes","Admin"],

colModel:[

{name:'id', index:'userid', width:55, editable:false, editoptions:{readonly:true,size:10}, hidden:true},

{name:'firstname', index:'firstname', width:100, editable:true, editoptions:{size:25}, editrules:{required:true}, resizable:true},

{name:'lastname', index:'lastname', width:100, editable:true, editoptions:{size:25}, editrules:{required:true}, resizable:true},

{name:'email', index:'email', width:200, editable:true, editoptions:{size:25}, editrules:{email:true, required:true}, resizable:true},

{name:'password', index:'password', width:100, editable:true, editoptions:{size:25}, editrules:{edithidden:true}, hidden:true, resizable:true },

{name:'groups', index:'groups', width:260, editable:true, edittype:"select", editoptions:{ multiple:true, size:3,

value: $.parseJSON( $.ajax({ url: appendSession('/async/groups.lasso'), type:'post', data: { x:1 }, dataType: 'json', async: false, success: function(data, result) { if (!result) alert('Failure to retrieve the groups.'); } }).responseText)

},

sortable:false, resizable:true},

{name:'notes', index:'notes', width:10, editable:true, edittype:"textarea", editrules:{edithidden:true}, hidden:true, editoptions:{rows:"3",cols:"26"}, sortable:false},

{name:'isadmin', index:'isadmin', width:60, editable:true, edittype:"checkbox", editoptions:{value:"Yes:No"}, align:"center" }

],

rowNum:10,

rowList:[10,20,30],

pager: '#pagernav',

sortname: "userid",

viewrecords: true,

sortorder: "desc",

caption:"Users Management",

editurl:appendSession("/async/users.lasso?x=2"),

height:210

});

$("#navgrid").jqGrid('navGrid','#pagernav',

{}, //options

{height:325,reloadAfterSubmit:false,closeAfterEdit:true,closeOnEscape:true}, // edit options

{height:325,reloadAfterSubmit:false,closeAfterAdd:true,closeOnEscape:true}, // add options

{reloadAfterSubmit:false,closeOnEscape:true}, // del options

{closeOnEscape:true} // search options

);

 Is there something I need to add into the add options to attach the new ID to the table?

28/02/2011
22:26
Avatar
Steffan
Member
Members
Forum Posts: 50
Member Since:
18/08/2008
sp_UserOfflineSmall Offline

I'm stuck. Any suggestions?

01/03/2011
20:52
Avatar
Steffan
Member
Members
Forum Posts: 50
Member Since:
18/08/2008
sp_UserOfflineSmall Offline

Oleg,

I've searched the documentation a few times and I'm not seeing any examples of how the data has to be formatted when returning the new ID back to the plugin. Do you have an example? Should it be JSON since I am using datatype: 'json' ? Should it be in the form of {id:1234}?

Thanks,
Steffan

01/03/2011
21:48
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

OK Steffan,

The datatype:'json' is not really important for the form editing which you use. Insetad of that the method afterSubmit is what you need to implement because you use reloadAfterSubmit:false option. You server have to return the id of new created row in any form want you will. In the simplest situation the server component, which are accessble under the editurl "/async/users.lasso?x=2″ which you use, can just return the string 1234 without any quotes as the result of "Add" operations. On "Delele" or "Edit" operation it should return empty body (empty string). Then your version of the afterSubmit function can be

afterSubmit: function(responseText,postdata) {
    return [true,"",responseText];
}

In the case you will use the text from the server response as the id of the new row. You can set the afterSubmit for all grids with respect of

jQuery.extend(jQuery.jgrid.edit,
    {
        reloadAfterSubmit:false,
        closeAfterAdd:true,
        closeAfterEdit:true,
        closeOnEscape:true,
        afterSubmit: function (responseText, postdata) {
            return [true,"",responseText];
        }
    }
);

Best regards
Oleg 

02/03/2011
08:07
Avatar
Steffan
Member
Members
Forum Posts: 50
Member Since:
18/08/2008
sp_UserOfflineSmall Offline

Well, we're getting closer. Its odd. This is what the row looks like inthe Safari element inspector

<tr id="[object XMLHttpRequest]" role="row" class="ui-widget-content jqgrow ui-row-ltr ui-state-highlight ui-state-hover" aria-selected="true"><td role="gridcell" aria-describedby="navgrid_id" style="display:none;" title="[object XMLHttpRequest]">[object XMLHttpRequest]</td><td role="gridcell" aria-describedby="navgrid_firstname" style="" title="george">george</td><td role="gridcell" aria-describedby="navgrid_lastname" style="" title="lopez">lopez</td><td role="gridcell" aria-describedby="navgrid_email" style="" title="george@lopez.com">george@lopez.com</td><td role="gridcell" aria-describedby="navgrid_password" style="display:none;" title="fsfsdfs">fsfsdfs</td><td role="gridcell" aria-describedby="navgrid_groups" style="" title="Group 1,Group 2,Group 3,Group 4,Group 5,Group 6,Group 7,Group 8">Group 1,Group 2,Group 3,Group 4,Group 5,Group 6,Group 7,Group 8</td><td role="gridcell" aria-describedby="navgrid_notes" style="display:none;" title="test">test</td><td role="gridcell" aria-describedby="navgrid_isadmin" style="text-align:center;" title="Yes">Yes</td></tr>

Notice what the id is. Did I make a mistake in there? I implented the code as you suggested. I don't see a section on the afterSubmit in detail within the wiki to understand the  return [true,"",responseText]; Below is my constructor with your addition.

$("#navgrid").jqGrid({

url:appendSession("/async/users.lasso?x=1"),

datatype: "json",

hidegrid: false,

colNames:["User ID","First Name","Last Name","Email","Password","Groups","Notes","Admin"],

colModel:[

{name:'id', index:'userid', width:55, editable:false, editoptions:{readonly:true,size:10}, hidden:true},

{name:'firstname', index:'firstname', width:100, editable:true, editoptions:{size:25}, editrules:{required:true}, resizable:true},

{name:'lastname', index:'lastname', width:100, editable:true, editoptions:{size:25}, editrules:{required:true}, resizable:true},

{name:'email', index:'email', width:200, editable:true, editoptions:{size:25}, editrules:{email:true, required:true}, resizable:true},

{name:'password', index:'password', width:100, editable:true, editoptions:{size:25}, editrules:{edithidden:true}, hidden:true, resizable:true },

{name:'groups', index:'groups', width:260, editable:true, edittype:"select", editoptions:{ multiple:true, size:3,

value: $.parseJSON( $.ajax({ url: appendSession('/async/groups.lasso'), type:'post', data: { x:1 }, dataType: 'json', async: false, success: function(data, result) { if (!result) alert('Failure to retrieve the groups.'); } }).responseText)

},

sortable:false, resizable:true},

{name:'notes', index:'notes', width:10, editable:true, edittype:"textarea", editrules:{edithidden:true}, hidden:true, editoptions:{rows:"3",cols:"26"}, sortable:false},

{name:'isadmin', index:'isadmin', width:60, editable:true, edittype:"checkbox", editoptions:{value:"Yes:No"}, align:"center" }

],

rowNum:10,

rowList:[10,20,30],

pager: '#pagernav',

sortname: "userid",

viewrecords: true,

sortorder: "desc",

caption:"Users Management",

editurl:appendSession("/async/users.lasso?x=2"),

height:210

});

$("#navgrid").jqGrid('navGrid','#pagernav',

{}, //options

{height:325,reloadAfterSubmit:false,closeAfterEdit:true,closeOnEscape:true}, // edit options

{height:325,reloadAfterSubmit:false,closeAfterAdd:true,closeOnEscape:true, afterSubmit: function(responseText,postdata) { return [true,"",responseText]; } }, // add options

{reloadAfterSubmit:false,closeOnEscape:true}, // del options

{closeOnEscape:true} // search options

);

02/03/2011
08:33
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

I supose the error is in my previous code. The afterSubmit should be:

afterSubmit: function(response,postdata) {
    return [true,"",response.responseText];
}

Best regards
Oleg

03/03/2011
04:29
Avatar
Steffan
Member
Members
Forum Posts: 50
Member Since:
18/08/2008
sp_UserOfflineSmall Offline

Oleg,

Thank you so much!!

For the record, if anyone else gets stuck and this is Google indexed, here is the final constructor!

$("#navgrid").jqGrid({

url:appendSession("/async/users.lasso?x=1"),

datatype: "json",

hidegrid: false,

colNames:["User ID","First Name","Last Name","Email","Password","Groups","Notes","Admin"],

colModel:[

{name:'id', index:'userid', width:55, editable:false, editoptions:{readonly:true,size:10}, hidden:true},

{name:'firstname', index:'firstname', width:100, editable:true, editoptions:{size:25}, editrules:{required:true}, resizable:true},

{name:'lastname', index:'lastname', width:100, editable:true, editoptions:{size:25}, editrules:{required:true}, resizable:true},

{name:'email', index:'email', width:200, editable:true, editoptions:{size:25}, editrules:{email:true, required:true}, resizable:true},

{name:'password', index:'password', width:100, editable:true, editoptions:{size:25}, editrules:{edithidden:true}, hidden:true, resizable:true },

{name:'groups', index:'groups', width:260, editable:true, edittype:"select", editoptions:{ multiple:true, size:3,

value: $.parseJSON( $.ajax({ url: appendSession('/async/groups.lasso'), type:'post', data: { x:1 }, dataType: 'json', async: false, success: function(data, result) { if (!result) alert('Failure to retrieve the groups.'); } }).responseText)

},

sortable:false, resizable:true},

{name:'notes', index:'notes', width:10, editable:true, edittype:"textarea", editrules:{edithidden:true}, hidden:true, editoptions:{rows:"3",cols:"26"}, sortable:false},

{name:'isadmin', index:'isadmin', width:60, editable:true, edittype:"checkbox", editoptions:{value:"Yes:No"}, align:"center" }

],

rowNum:10,

rowList:[10,20,30],

pager: '#pagernav',

sortname: "userid",

viewrecords: true,

sortorder: "desc",

caption:"Users Management",

editurl:appendSession("/async/users.lasso?x=2"),

height:210

});

$("#navgrid").jqGrid('navGrid','#pagernav',

{}, //options

{height:325,reloadAfterSubmit:false,closeAfterEdit:true,closeOnEscape:true}, // edit options

{height:325,reloadAfterSubmit:false,closeAfterAdd:true,closeOnEscape:true, afterSubmit: function(response,postdata) { return [true,"",response.responseText]; } }, // add options

{reloadAfterSubmit:false,closeOnEscape:true}, // del options

{closeOnEscape:true} // search options

);

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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