Forum


15:38

30/05/2009

I have a Master/Detail grid setup, each pulls data from a different table with a common key. The master grid contains a unique “user_id” value for each row.
How do I pass this “user_id” value from the selected row of the master grid AUTOMATICALLY when I'm adding a record to the detail grid?
I don't want to have to add the same “user_id” each time a record is added to the detail grid… it should be automatically entered according to the row they've selected in the Master Grid.
08:37

30/05/2009

I actually only need the rowid selected… I've read all the posts after searching for master, but none of them work. Here's my code:
$(”#list”).jqGrid({
url:'data/dashboard.php',
datatype: 'xml',
mtype: 'GET',
colModel :[
{name:'fname', index:'fname', label:'First Name', width:130, editable:true,editoptions:{size:30}},
{name:'lname', index:'lname', label:'Last Name', width:150, editable:true,editoptions:{size:30}},
{name:'logon', index:'logon', label:'Last Logon', width:120, align:'center',editable:false},
{name:'start', index:'start', label:'Start Date', width:120, align:'center',editable:true,editoptions:{size:20}},
{name:'userid', index:'userid', label:'User ID', width:150,editable:true,editoptions:{size:40}},
{name:'note', index:'note', label:'Notes', width:150, sortable:false,editable:true,edittype:"textarea", editoptions:{rows:"3",cols:"50"}}
],
pager: $('#pager'),
rowNum:60,
rowList:[20,40,60],
sortname: 'lname',
sortorder: “asc”,
viewrecords: true,
imgpath: 'themes/steel/images',
caption: 'Customers',
height:300,
onSelectRow: function(ids) {
if(ids == null) {
ids=0;
if(jQuery(”#list_detail”).getGridParam('records') > 0 ) {
jQuery(”#list_detail”).setGridParam({url:”data/subgrid.php?&q=1&id=”+ids,page:1})
.setCaption(”License Detail: “+ids)
.trigger('reloadGrid');
}
} else {
jQuery(”#list_detail”).setGridParam({url:”data/subgrid.php?&q=1&id=”+ids,page:1})
.setCaption(”License Detail: “+ids)
.trigger('reloadGrid');
}
}
}).navGrid('#pager',
{add: true, edit: true, del: true, search: true}, //options
{editCaption:'Edit License', height:200,width:600,reloadAfterSubmit:false,url:'useredit.php'}, // edit options
{editCaption:'Add License', height:200,width:600,reloadAfterSubmit:false,url:'useredit.php'}, // add options
{caption:'Delete License', reloadAfterSubmit:false,url:'useredit.php'}, // del options
{width:600} // search options
);
$(”#license”).click(function(){
var gr = jQuery(”#list”).getGridParam('selrow');
if( gr != null ) jQuery(”#list”).editGridRow(gr,{height:280,reloadAfterSubmit:false});
else alert(”Please Select a Customer if you would like to Add a New License”);
});
// Begin License Subgrid
$(”#list_detail”).jqGrid({
height: 100,
width:851,
url:'data/subgrid.php?q=1&id=0',
datatype: “xml”,
mtype: “GET”,
colModel:[
{name:'user_id',index:'user_id', label:'User', align:'center', hidden:true, edittype:"text", editrules:{number:true}, width:180, editable:true, editoptions:{value:""+user_id, size:30}},
{name:'app',index:'app', label:'Application', width:200, align:'center', editable:true, edittype:"select",
editoptions:{value:"<?php include 'includes/dbconfig.inc.php';
$con = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());
mysql_select_db($database) or die("Error connecting to db.");
$query = "SELECT id,app FROM appid";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
echo $row['id'] . “:” . $row['app'] . “;”;
}
mysql_close($con); ?>”}},
{name:'expiration',index:'expiration', label:'Expires', align:'center', editrules:{date:true}, datefmt:'yyyy-mm-dd', width:180, editable:true,editoptions:{size:30}}
],
rowNum:5,
rowList:[5,10,20],
imgpath: 'themes/steel/images',
pager: jQuery('#pager_detail'),
sortname: 'app',
viewrecords: true,
sortorder: “asc”,
caption:”License Detail”
}).navGrid('#pager_detail',
{add:true,edit:true,del:true,search:false}, //options
{height:200,width:600,reloadAfterSubmit:true,url:'licenseedit.php'}, // edit options
{height:200,width:600,reloadAfterSubmit:false,url:'licenseedit.php'}, // add options
{reloadAfterSubmit:false,url:'licenseedit.php'}, // del options
{width:600} // search options
);
});
I've tried this option from another post, but I'm using only navGrid for editing (no inline editing):
jQuery(”#detail”).jqGrid({…}).navGrid(”#pgdetail”,{…},
{…}, //edit
{…
beforeShowForm: function(formid) {
// we should get the id of the master here
mid = jQuery(”#master”).getGridParam(”selrow”);
if (mid != null ) {
// now we can set it in editurl
jQuery(”#detail”).setGridParam({editurl:”myurlhere.php?masterid=”+mid});
}
}
….
How do I set the "add" url only?
Most Users Ever Online: 715
Currently Online:
75 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