Forum
05:44
16/06/2010
I am having an issue with sorting since upgrading from version 3.6.5 to version 3.7.1. Basically the data in the grid is being truncated to 20 items. I do not have paging configured for the grid.
The code below should demonstrate my issue. Notice when you click the sort button that the ids either go from 29 down to 10 or from 1 up to 20, depending on the sort order.
This behaviour is different to version 3.6.5. Is there an additional property that i can configure to get the behaviour from 3.6.5 where all rows would be displayed?
<html>
<head>
<script src="js/jquery-1.4.2.min.js" type="text/javascript">
</script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript">
</script>
<link rel="stylesheet" href="css/ui.jqgrid.css"/>
</head>
<body>
<script type="text/javascript">
$(function() {
jQuery("#list4").jqGrid({
datatype: "local",
height: 250,
colNames:['Inv No','Client'],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'name',index:'name', width:100},
],
caption: "Manipulating Array Data" });
var mydata = [
{id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"3",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
{id:"4",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"5",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"6",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
{id:"7",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"8",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"9",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"} ,
{id:"10",invdate:"2007-09-01",name:"test3",note:"note4",amount:"400.00",tax:"30.00",total:"430.00"} ,
{id:"11",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"12",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"13",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
{id:"14",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"15",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"16",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
{id:"17",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"18",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"19",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"} ,
{id:"20",invdate:"2007-09-01",name:"test3",note:"note4",amount:"400.00",tax:"30.00",total:"430.00"} ,
{id:"21",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"22",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"23",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
{id:"24",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"25",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"26",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
{id:"27",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"28",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"29",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"}
];
for(var i=0;i<=mydata.length;i++)
jQuery("#list4").jqGrid('addRowData',i+1,mydata[i]);
$('#mybutton').click(function() {
$('#list4').jqGrid('sortGrid','id',false);
});
});
</script>
<button id="mybutton">Click to Sort</button>
<table id="list4"></table>
</body>
</html>
06:12
16/06/2010
Doing some more research, I notice the 'rowNum' property on the grid that defaults to 20.
If i add a property -
, it now displays rows 29 down to 2 or rows 1 down to 28, depending on the sort order with version 3.7.1. On version 3.6.5, it displays all rows (29-1 / 1-29) correctly.
So, even with the property added:
there is still an 'off by 1' issue in the sorting code in 3.7.1, by the looks of it.
09:36
Moderators
30/10/2007
Hello,
It is not a good idea in this case to use addRowData.
Also you can simple replace
for(var i=0;i<=mydata.length;i++)
jQuery("#list4").jqGrid('addRowData',i+1,mydata[i]);
with
jQuery("#list4").jqGrid({
datatype: "local",
data : mydata,
...
});
It is a more natural way to have paging.
Instead I will check your example.
Best Regards.
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.
09:50
16/06/2010
Thanks for the suggestion Tony.
For the purposes of demonstrating this bug, i just took one of the jqgrid demos and modified it.
In my real code, the data is not available at the time of constructing the grid however i do pass it all to addRowData() in 1 method call, rather than in a loop as is shown in this code.
I hope you manage to find the issue 🙂
09:22
Moderators
30/10/2007
Hello,
Sorry, I do not see other way
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.
11:14
16/06/2010
gal_ga,
sorry but you have kind of hijacked this thread. perhaps you want to start a new thread to ask questions about your issue. FYI, addRowData still works to add single rows of data.
tony,
regarding the sorting issue, I have tracked down the issue to line 1364 in grid.base.js
In my case, page = 0 and records per page = -1.
Therefore it is calling queryResults.slice(0, -1) and removing the last element from the array.
I'm not sure of a better way to do this but possibly just doing:
if( recordsperpage != -1 )
{
queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
}
will solve it.
13:30
Moderators
30/10/2007
Hello,
Thanks.
Mybe you will need to do
rowNum: 10,
rowTotal : -1
according to the examples for obtaining the data at once and manipulate it locally,
or change the rowNum to value greater than -1 after the grid loads.
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.
Most Users Ever Online: 715
Currently Online:
40 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