Forum
Topic RSS
Hello all,
I have a grid that works fairly well. Now, I wish to have a dynamic url.
For example,
http:www.mysite.com/getgame.php?id=123
This will change based on the id.
Within the grid, I have the 'url' set to the page name (getgame.php)
[CODE]
jQuery("#contacts").jqGrid({
url:"getgame.php",
datatype: 'json',
colNames:['Contact No','Last Name', 'First Name', 'Type','Email','Phone', 'Fax', 'Note'],
colModel :[
{name:'member_contacts_id',
index:'member_contacts_id',
width:100,
hidden:true,
editable:false,
editoptions:{
readonly:true,
size:10
}
},
{name:'last', index:'last', width:120, align:'right', editable:true,editoptions:{size:30}},
{name:'first', index:'first', width:120, align:'right', editable:true,editoptions:{size:30}},
{name:'type',
index:'type',
width:70,
hidden:true,
editable: true,
edittype:"select",
editoptions:
{
value:"Coach:Coach;Trainer:Trainer;Referee:Referee"
},
editrules:{edithidden:true}
},
{name:'email', index:'email', width:200, align:'right', editable:true,editoptions:{size:30}},
{name:'phone', index:'phone', width:110, align:'right', editable:true,editoptions:{size:30}},
{name:'fax', index:'fax', width:110, align:'right', editable:true,editoptions:{size:30}},
{name:'note',
index:'note',
width:100,
sortable:false,
hidden:true,
editable: true,
edittype:"textarea",
editoptions:{rows:"5",cols:"30"},
editrules:{edithidden:true}
}
],
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'member_contacts_id',
sortorder: 'asc',
viewrecords: true,
caption: 'Contacts',
height:"100%",
editurl:"_editContacts.php'",
grouping: true,
groupingView : {
groupField : ['type'],
groupColumnShow : [false],
groupText : ['<b>{0} - {1} Contact(s)</b>'],
groupCollapse : true,
groupOrder: ['asc'],
groupDataSorted : true
}
});
[\CODE]
How do I set and pass the id number that will change?
Thank you for any help with this.
John
It's not who I am underneath, but what I do that defines me.
22:42
10/08/2009
OfflineFirst of all you should be careful with the usage of url in the form "http:www.mysite.com/getgame.php?id=123" because of Same Origin Policy restrictions. You can get per ajax only data from the same web site. So to have the problem no time you should use always url without protocol, domain and port prefix: "/blabla/getgame.php?id=123" or "getgame.php?id=123".
Because you use HTTP GET for requests to the server and you want append the url with additional parameter "id=123" you can do this without modification of url. Just use postData option of jqGrid
postData: {id: 123}
or
postData: {id: myId}
where myId is a var which has the value which you need (like 123).
You can also use functions as a value of some postData properties like
postData: {id: function() {
if (jQuery("#onlyMySw").is(':checked')) {
return 123;
} else {
return 456;
}
}
}
The last approach has a large advantage, because the function will be called every time during grid refresh (for example, in case of choose new sort order or switching between pages and so on. In the example above the url will be appended with parameter id=123 if checkbox with id="onlyMySw" is checked and with id=456 if it is not checked.
To read more about the last approach see my answer on the stackoverflow.com.
Best regards
Oleg
Solved the problem.
Within the navGrid, I added "editData:{id:value}" in the add, edit options.
{search:false,view:true}, //options
{jqModal:true,checkOnUpdate:true,savekey: [true,13], navkeys: [true,38,40], checkOnSubmit : true, reloadAfterSubmit:false, closeOnEscape:true, bottominfo:"Fields marked with (*) are required", width: 400, editData:{id:value}}, // edit options
{jqModal:true,checkOnUpdate:true,savekey: [true,13], navkeys: [true,38,40], checkOnSubmit : true, reloadAfterSubmit:false, closeOnEscape:true,bottominfo:"Fields marked with (*) are required", width: 400, editData:{id: value}}, // add options
{reloadAfterSubmit:false,jqModal:false, closeOnEscape:true}, // del options
{}, // search options
{navkeys: [true,38,40], height:250, width: 300,jqModal:false,closeOnEscape:true} // view options
)
});
John
It's not who I am underneath, but what I do that defines me.
Most Users Ever Online: 994
Currently Online:
30 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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66
Log In
Home