Forum



19:25

21/09/2009

My grid loads data, sorts the data, but will not page. When the page button is clicked the "Loading" message appers briefly but the data does not change. The same result, if I manualy change the page number.
In firebug, I can see the request from jQgrid and the response from the server. The response is properly formatted jSon.
Here is my html:
<script type="text/javascript">
$(document).ready(function(){
jQuery("#wdData").jqGrid({
url:'../testJson.php?q=2',
datatype: "json",
colNames:['ID','Item', 'Value'],
colModel:[
{name:'id',index:'id', width:55, hidden: true },
{name:'item',index:'item', width:490, sortable: true},
{name:'value',index:'value', width:300}],
rowNum:20,
rowList:[10,20,30,40],
pager: '#pager2',
sortname: 'item',
viewrecords: true,
sortorder: "desc",
caption:"Weather Display TestTags--Json",
width:600,
height:800
});
jQuery("#wdData").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false});
});
</script>
</head>
<body>
<div id ="content"><table id="wdData"></table><div id="pager2"></div> </div>
</body>
</html>
The page itself is at: http://billhogsett.com/wd/wd2/wd-JQGrid/testJSon2.html
Can someone point me to the error of my ways?
Thanks!
Bill
00:40

14/07/2011

Well I have this code in a page aspx
{
iConn = new System.Data.Odbc.OdbcConnection(ConfigurationManager.AppSettings["ConexionStringMySql"]);
string SQL = "SELECT id_realizador, upper(nombre), cargo, Case cargo When '1' then 'SUPERVISOR' When '2' Then 'OPERADOR' When '3' Then 'TECNICO' When '4' Then 'CLIENTE' When '5' Then 'SUPERVISOR EXTERNO' When '6' Then 'OPERADOR EXTERNO' Else cargo End, lower(e_mail) FROM t_realizadores WHERE 1";
if (nm.Trim() != "")
{
SQL = SQL + " AND nombre Like '%" + nm.Trim() + "%'";
}
if (cd.Trim() != "0")
{
SQL = SQL + " AND cargo = '" + cd.Trim() + "'";
}
SQL = SQL + " Order By id_realizador";
iConn.Open();
oDataSet = new DataSet();
oAdapter = new OdbcDataAdapter(SQL, (OdbcConnection)iConn);
oAdapter.Fill(oDataSet);
iConn.Close();
List<TraeUsuarios> Listado = new List<TraeUsuarios>();
for (int i = 0; i < oDataSet.Tables[0].Rows.Count; i++)
{
if (oDataSet.Tables[0].Rows[i].ItemArray[1].ToString().Trim() != "")
{
Listado.Add(new TraeUsuarios { Id = Convert.ToInt32(oDataSet.Tables[0].Rows[i].ItemArray[0].ToString().Trim()), Nombre = oDataSet.Tables[0].Rows[i].ItemArray[1].ToString().Trim(), CargoId = oDataSet.Tables[0].Rows[i].ItemArray[2].ToString().Trim(), Cargo = oDataSet.Tables[0].Rows[i].ItemArray[3].ToString().Trim(), Email = oDataSet.Tables[0].Rows[i].ItemArray[4].ToString().Trim() });
}
}
return GridUsuariosDatos(((Listado.Count) / 10) + 1, 1, Listado.Count, Listado);
}
public string GridUsuariosDatos(int noOfPages, int startPage, int noOfRecords, List<TraeUsuarios> list)
{
var gridData = new
{
page = startPage,
total = noOfPages,
records = noOfRecords,
rows = list,
};
var jsonSerializer = new JavaScriptSerializer();
return jsonSerializer.Serialize(gridData);
}
public class TraeUsuarios
{
public TraeUsuarios()
{
Id = 0;
Nombre = string.Empty;
CargoId = string.Empty;
Cargo = string.Empty;
Email = string.Empty;
}
public int Id { get; set; }
public string Nombre { get; set; }
public string CargoId { get; set; }
public string Cargo { get; set; }
public string Email { get; set; }
}
And This in the page that i show the grid
url: 'FetchGrillas.aspx?pvu=GU&nm=&cd=0',
datatype: 'json',
mtype: 'POST',
colNames: ['Id', 'Nombre', 'CargoId', 'Cargo', 'Email'],
colModel: [
{ name: 'Id', index: 'Id', width: 20, editable: false, sortable: false, editoptions: { readonly: true, size: 5} },
{ name: 'Nombre', index: 'Nombre', width: 250, align: "left", editable: false, sortable: false, size: 100 },
{ name: 'CargoId', index: 'CargoId', width: 50, align: 'left', editable: false, sortable: false },
{ name: 'Cargo', index: 'Cargo', width: 150, align: 'left', editable: false, sortable: false },
{ name: 'Email', index: 'Email', width: 300, align: 'left', editable: false, sortable: false }
],
rowNum: 10,
rowList: [10, 20],
pager: '#paginaciongrilla',
sortname: 'Id',
viewrecords: true,
sortorder: "desc",
jsonReader: { repeatitems: false },
caption: 'Usuarios'
, height: 255
, onSelectRow: function() {
var id = jQuery("#grillausers").jqGrid('getGridParam', 'selrow');
if (id) {
var ret = jQuery("#grillausers").jqGrid('getRowData', id);
alert(ret.Id);
return false;
}
}
});
But when i press the next page button i alway return the first page 🙁
Please Help 😛
17:52

28/07/2011

Is the response from the server the second page, or is it the first page over and over? It sounds like a server-side code problem. The server gets the row numbers the grid wants, and it's the responsibility of the server-side code to get those rows from the database. In most databases that would be the LIMIT clause (in PHP, you'd use $start = $limit*$page – $limit; for the start and $limit for the liimit.)
15:22

28/07/2011

jqGrid sends the start record number and number of records to the server. You tell the database to give you those rows. There's no reason to write paging code yourself, since jqGrid does that for you. Just use ' ... LIMIT '.$start.', '.$limit, or whatever your particular database uses (some use "limit to x, y rows", some use "limit x,y", some use other syntax).
Most Users Ever Online: 715
Currently Online:
55 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