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_Related Related Topics sp_TopicIcon
How to do default sorting when grid first time load
02/12/2010
14:42
Avatar
dm
Member
Members
Forum Posts: 4
Member Since:
02/12/2010
sp_UserOfflineSmall Offline

We have grid with say 10 columns. These 10 columns are not directly mapped with database, so I can not use order by clause. Now I want to sort the grid when it show data first time base on column no. 3. How to achive this sorting ?

I have achived this by below script.....

gridComplete : function(){
                        $("#column3").click();
},

But this approch is not working consistently? Some time it sort asc or sometime desc orders? also in case if data is more than 700 rows the grid's javascript got currupted?

Please suggest me some right approch to solve the sorting issue???Smile

02/12/2010
15:46
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hi dm,

I suppose your problem is in the way how you fill the grid. The best way will be the usage of data parameter of the jqGrid. In the way the data filled in the grid will be automatically sorted and the first page of data displayed. So the user can work with the grid in very comfortable way using local sorting by another column as default (column no. 3 in your case), go to another page and searching/filtering of the data. You can use Toolbar Searching if needed and so on.

If you do want to add the rows in old way with respect of addRowData for example you will have to reload the grid with the code like $("#list").trigger("reloadGrid"); after the grid is full filled to force the sorting of the data.

If all this not help, you should post the whole code (JavaScript + HTML) which can be used to reproduce your problem.

Best regards,
Oleg

02/12/2010
20:42
Avatar
SomethingNew
Member
Members
Forum Posts: 8
Member Since:
26/08/2010
sp_UserOfflineSmall Offline

Hi,

I'm having the same issue, I need to sort locally on page load because my db query won't allow server side sorting.  I'm not sure if I understand your first suggestion Oleg, but when I do $("#list").trigger("reloadGrid"); it doesn't work.  I'm doing this inside of the loadComplete event, which I've heard is having similar issues. Even when trying to do the sortGrid() method inside of loadComplete it doesn't actually sort, it just displays the sort arrows.  Does anyone have a solution?

Thanks in advance

03/12/2010
01:24
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Sorry SomethingNew,

It is very difficult to explain the taste of something without to taste of it. Exactly the same is true if we write something about the code. Why you don't just post the code which you mean?

What I mean is very easy. Look at this example. One prepare an array with data which include additional 'id' property if it not exist already in the grid. Then create a jqGrid using the data as input. It's all. The data will be automatically sorted and paged. So you have no problem with the sorting and paging of the data after the filling jqGrid with addRowData used in a loop.

If my example not help you, then just post your example which has the problem.

Best regards
Oleg 

03/12/2010
08:29
Avatar
dm
Member
Members
Forum Posts: 4
Member Since:
02/12/2010
sp_UserOfflineSmall Offline

SomethingNew, we are on the same page and getting similar issue.

OlegK, i am using json to load the data into grid. But data that loaded first time is not sorted by default base on column3 but we want to show data sorted base on column3 first time only. We don't want user to click on column3 and then it sort.

According to your example data sorted base on id column by default. Now suppose same sorted data (means sorted by id) coming from server side and you want it to sort it base on amount column before it display on grid first time. I was able to do this by code:

gridComplete : function(){
                        $("#column3″).click();
},

But it has performance and some other issues

I hope I have cleared my point, please let me know if you need more inputs to understand our problem.  Please suggest us right way to solve it.

03/12/2010
21:01
Avatar
SomethingNew
Member
Members
Forum Posts: 8
Member Since:
26/08/2010
sp_UserOfflineSmall Offline

Ok that worked, if I did datatype of local and with array data, instead of json and loadonce it worked like a charm.

Thanks,

SomethingNew

03/12/2010
23:16
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello dm,

the information that you use loadonce:true parameter is very important. In general you should send the data from the server in the sorted order. It you don't do this you can reload the grid, but because of usage of loadonce:true parameter you should do this a little tricky:

loadComplete: function(data) {
    if (myGrid.jqGrid('getGridParam','datatype') === "json") {
        setTimeout(function(){
            myGrid.trigger("reloadGrid");
        },100);
    }
}

Next time it is better to post whole jqGrid definition. The person which will read the code could probably find some important settings (like in your case) which could be important to find a working solution.

Here is a small code example which you can see live.

Best regards
Oleg 

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
61 Guest(s)

Currently Browsing this Page:
2 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