Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Sorting bug in 3.7.1?
16/06/2010
05:44
Avatar
Fatal
Member
Members
Forum Posts: 5
Member Since:
16/06/2010
sp_UserOfflineSmall Offline

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>

16/06/2010
06:12
Avatar
Fatal
Member
Members
Forum Posts: 5
Member Since:
16/06/2010
sp_UserOfflineSmall Offline

Doing some more research, I notice the 'rowNum' property on the grid that defaults to 20.

If i add a property -

rowNum: -1

, 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:

rowNum: -1

there is still an 'off by 1' issue in the sorting code in 3.7.1, by the looks of it.

16/06/2010
09:36
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

16/06/2010
09:50
Avatar
Fatal
Member
Members
Forum Posts: 5
Member Since:
16/06/2010
sp_UserOfflineSmall Offline

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 🙂

16/06/2010
12:25
Avatar
gal_ga
Member
Members
Forum Posts: 10
Member Since:
07/03/2010
sp_UserOfflineSmall Offline

Hi Tony,

I also have issues with the use of:

for(var i=0;i<=mydata.length;i++){

jQuery("#list4″).jqGrid('addRowData',i+1,mydata[i]);

}

Even if there is a better way in 3.7.x - I still have an old code which does it and currently prefer not to modify.

20/06/2010
09:22
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

20/06/2010
09:45
Avatar
gal_ga
Member
Members
Forum Posts: 10
Member Since:
07/03/2010
sp_UserOfflineSmall Offline

Just to be sure I got you right. do you mean that a code like this:

for(var i=0;i<=mydata.length;i++) {

    jQuery("#list4″).jqGrid('addRowData',i+1,mydata[i]);

}

Which used to work, is no longer supported?

20/06/2010
11:14
Avatar
Fatal
Member
Members
Forum Posts: 5
Member Since:
16/06/2010
sp_UserOfflineSmall Offline

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

            queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );

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.

20/06/2010
13:30
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

20/06/2010
16:10
Avatar
Fatal
Member
Members
Forum Posts: 5
Member Since:
16/06/2010
sp_UserOfflineSmall Offline

hi tony,

Were you replying to my post or to gal_ga? I'm a bit confused.

Regardless, I believe that the fix I suggested should work. Could you please look at integrating it into the next revision of jqGrid?

cheers

Paul.

20/06/2010
16:39
Avatar
gal_ga
Member
Members
Forum Posts: 10
Member Since:
07/03/2010
sp_UserOfflineSmall Offline

Hi Paul,

Sorry for being "pushed" here.

Tony replied yours post and asked me to open my issue in different post.

Cheers,

Gal

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information