Forum


20:19

05/02/2009

Hi. Once again, Tony, I think you've done a marvelous job on this plugin. I'm working on one that is populated based on what the user selects from a select box. So far, when the user selects the option, the grid is populated. However, when the user changes the option in the select box, the server side program is called again, but it passes the same parameters as the first call. Here is my code if it will help:
$(document).ready(function()
{
$('#salesRepresentative').change(function()
{
var salesRep = $(this).val();
var columnNames = ['Customer Name','Quantity','Value'];
var columnModel =
[
{name:'id', resizable:false, index:'id', width:90, align:'left'},
{name:'quantity', resizable:false, index:'quantity', width:40, align:'center'},
{name:'value', resizable:false, index:'value', align:'center', width:40}
];
var gridwidth = $('.tableContainer').width();
gridwidth = gridwidth-26;
$("#results").trigger("reloadGrid").jqGrid(
{
url: "rinvinqs2?salesRepresentative="+$('#salesRepresentative').val(),
datatype: "json",
mtype: 'GET',
colNames: columnNames,
colModel: columnModel,
pager: jQuery('#pager2'),
pgtext: ' of',
rowNum: 50,
rowList: [10,20,50,100],
imgpath: "../javascript/JQGrid/themes/coffee/images",
sortname: 'quantity',
sortorder: "desc",
viewrecords: true,
caption: "Inventory Status By Sales Representative",
width: gridwidth,
height: '350px',
multiselect: false,
loadComplete: function()
{
var udata = $('#results').getUserData();
$("#t_results").css("text-align","right").html("<table style=\\"width: 100%;\\"><tr><td style=\\"width: 277px; text-align: right;\\">Total: </td><td style=\\"width: 94px; text-align: center;\\"><!--%totohwgt%--></td><td style=\\"width: 63px; text-align: center;\\">100</td><td style=\\"width: 74px; text-align: center;\\"><!--%perLBCost%--></td><td style=\\"width: 122px; text-align: center;\\"><!--%totslswgt%--></td><td style=\\"width: 86px; text-align: center;\\"><!--%monthsSupply%--></td><td style=\\"width: 86px; text-aign: center;\\"> </td></tr></table>");
$('#cb').prev().remove();
if($("#results").getGridParam("records")==0)
{
$('#noResults').dialog("open");
}
else
{
var page = $('#results').getGridParam("page");
var records = $('#results').getGridParam("records");
var recordsPP = $('#results').getGridParam("rowNum");
var x = records/recordsPP;
var returnArray = [];
if(x < page)
{
iterLimit = records%recordsPP;
}
else
{
iterLimit = recordsPP;
}
for(var i=1; i<=iterLimit; i++)
{
$('#'+i).children('td:first').next().addClass('link').css("cursor","pointer").css("color","blue").css("text-decoration","underline");
var ord = $('#'+i).children('td:first').next().text();
$('#'+i).children('td:first').next().click(function()
{
ord = $(this).text();
window.location.href = "RINVINQS2?salesRepresentative="+salesRep;
});
}
}
},
subGrid: true,
subGridRowExpanded: function(subgrid_id, row_id)
{
var subgrid_table_id;
subgrid_table_id = subgrid_id+"_t";
jQuery("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>");
jQuery("#"+subgrid_table_id).jqGrid(
{
url:"RINVINQS3?customerName="+row_id,
datatype: "json", //type of returned data
colNames: ['Item','Quantity','Unit Price','Value','Warehouse'],
colModel:
[
{name:"item",index:"item",width:80,key:true},
{name:"quantity",index:"quantity",width:130},
{name:"unitPrice",index:"unitPrice",width:80,align:"right"},
{name:"value",index:"value",width:80,align:"right"},
{name:"warehouse",index:"warehouse",width:80,align:"right",sortable:true},
],
width: 800,
rowNum: 20,
imgpath: "../javascript/JQGrid/themes/coffee/images",
sortname: 'item',
sortorder: "desc",
jsonReader:
{
repeatitems: false
}
})
},
shrinkToFit: true,
jsonReader :
{
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems : false
}
});
});
});
10:10

05/02/2009

I couldn't find an exact example of this, but I should be able to go off of the demonstration called “Search Big Sets.” The big difference was the following line:
$('#table_id').setGridParam({url:”pgmname?parameter1=”+
parameter1,page:1}).trigger(”reloadGrid”);
When I insert this line into my selectbox's .change() function, the JS bombs out and gives the following error message:
$(”#table_id”).setGridParam is not a function
I'm currently at version 3.4.1. Does anyone have an idea what might be causing this?
02:53

Moderators
30/10/2007

Hello,
I think you do not need to crate the grid every time you change the value from select box. Basically you need:
$(document).ready(function()
{
$("#mygrid").jqGrid({...});
$('#salesRepresentative').change(function()
{
var salesRep = $(this).val();
#("#mygrid").setGridParam({...}).triggre("reloadGrid");
}
});
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.
13:21

05/02/2009

With a lot of help from Nathan, I got it working. I made a lot of changes, and I'm not sure exactly what was causing it not to work, but here's my current code:
function ElementWidth(elem)
{
var w = $(elem).outerWidth() -(8*5)-2
alert(w);
return w;
}
function ChangeSalesRep()
{
var salesRep;
var surl
salesRep = document.getElementById("salesRepresentative").value;
if(salesRep=="")
{
salesRep="0";
}
//alert(salesRep);
surl = "RINVINQS2?salesRepresentative="+salesRep;
$('#results').setGridParam({url:surl, hiddengrid:false});
$('#results').setGridParam({hiddengrid:false});
$('#results').trigger("reloadGrid");
}
$(document).ready(function()
{
var columnNames = ['Customer Name','Quantity','Value'];
var columnModel =
[
{name:'id', resizable:false, index:'id', width:90, align:'left'},
{name:'quantity', resizable:false, index:'quantity', width:40, align:'center'},
{name:'value', resizable:false, index:'value', align:'center', width:40}
];
var gridwidth = $('.tableContainer').width();
gridwidth = gridwidth-26;
$("#results").jqGrid(
{
url: "rinvinqs2?salesRepresentative="+document.getElementById("salesRepresentative").value,
//hiddengrid:true,
datatype: 'json',
mtype: 'GET',
colNames: columnNames,
colModel: columnModel,
pager: $('#pager2'),
pgtext: ' of',
rowNum: 50,
rowList: [10,20,50,100],
imgpath: "../javascript/JQGrid/themes/coffee/images",
sortname: 'quantity',
sortorder: "desc",
viewrecords: true,
caption: "Inventory Status By Sales Representative",
width: gridwidth,
height: '200px',
multiselect: false,
loadComplete: function()
{
var udata = $('#results').getUserData();
$('#t_results').css("text-align","right").html("<table style=\\"width: 100%;\\"><tr><td style=\\"width: 277px; text-align: right;\\">Total: </td><td style=\\"width: 94px; text-align: center;\\"><!--%totohwgt%--></td><td style=\\"width: 63px; text-align: center;\\">100</td><td style=\\"width: 74px; text-align: center;\\"><!--%perLBCost%--></td><td style=\\"width: 122px; text-align: center;\\"><!--%totslswgt%--></td><td style=\\"width: 86px; text-align: center;\\"><!--%monthsSupply%--></td><td style=\\"width: 86px; text-aign: center;\\"> </td></tr></table>");
$('#cb').prev().remove();
if($('#results').getGridParam("records")==0)
{
//$('#noResults').dialog("open");
}
else
{
var page = $('#results').getGridParam("page");
var records = $('#results').getGridParam("records");
var recordsPP = $('#results').getGridParam("rowNum");
var x = records/recordsPP;
var returnArray = [];
if(x < page)
{
iterLimit = records%recordsPP;
}
else
{
iterLimit = recordsPP;
}
for(var i=1; i<=iterLimit; i++)
{
$('#'+i).children('td:first').next().addClass('link').css("cursor","pointer").css("color","blue").css("text-decoration","underline");
var ord = $('#'+i).children('td:first').next().text();
$('#'+i).children('td:first').next().click(function()
{
ord = $(this).text();
window.location.href = "RINVINQS3?salesRepresentative="+document.getElementById("salesRepresentative").value;
});
}
}
},
subGrid: true, //If set to true this enables using a subgrid. If the subGrid is enabled, an additional column at left side is added to the basic grid. This column contains a 'plus' image which indicates that the user can click on it to expand the row. By default all rows are collapsed.
subGridRowExpanded: function(subgrid_id, row_id)
{
// subgrid_id is an id of the div tag created within a table
// the row_id is the id of the row
// If we want to pass additional parameters to the url we can use
// the method getRowData(row_id) - which returns associative array in type name-value
// here we can easily construct the following
var subgrid_table_id;
subgrid_table_id = subgrid_id+"_t";
jQuery("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>");
jQuery("#"+subgrid_table_id).jqGrid(
{
url:"RINVINQS3?id="+row_id+"&salesRep="+document.getElementById("salesRepresentative").value, //specifies program to retrieve cell data
datatype: "json", //type of returned data
colNames: ['<div style="width: 100%; text-align: center;">Division<br />Number</div>','<br />Name','<div style="width: 100%; text-align: center;"><br />On Hand Weight</div>','<div style="width: 100%; text-align: center;">% of<br />Total</div>','<div style="width: 100%; text-align: center;">Per Lb<br />Cost</div>','<div style="width: 100%; text-align: center;">Avg Monthly<br />Sales Wgt</div>','<div style="width: 100%; text-align: center;">Months<br />Supply</div>','<div style="width: 100%; text-align: center;">Turnover<br />Rate</div>'], //column names
colModel:
[
{name:"divisionNumber",index:"divisionNumber",width:60,key:true,align:"center",sortable:false},
{name:"divisionName",index:"divisionName",width:180,align:"left",sortable:false},
{name:"onHandWeight",index:"onHandWeight",width:90,align:"center",sortable:false},
{name:"percentOfTotal",index:"percentOfTotal",width:50,align:"center",sortable:false},
{name:"perLbCost",index:"perLbCost",width:50,align:"center",sortable:false},
{name:"avgMonthlyWeight",index:"avgMonthlySales",width:80,align:"center",sortable:false},
{name:"monthsSupply",index:"monthsSupply",width:60,align:"center",sortable:false},
{name:"turnoverRate",index:"turnoverRate",width:60,align:"center",sortable:false},
],
//height: 100, //height of subgrid
width: 800, //width of subgrid
rowNum:20, //number of rows to display initially in subgrid
imgpath: "../javascript/JQGrid/themes/green/images", //what theme to use with subgrid
sortname: 'divisionNumber', //initial sorted column name
sortorder: "asc", //initial sort order
jsonReader:
{
repeatitems: false
}
})
},
shrinkToFit: true,
jsonReader:
{
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems : false
}
});
});
Most Users Ever Online: 715
Currently Online:
88 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