Forum


18:49

05/02/2009

Hi Tony,
Great job with the jqGrid! I do have a question though - I am using this with JSON data and since I don't want the grid to be making requests (GET/POST) I load my own json data into the grid. (using addJSONData). However, for some reason when that happens the grid does not get sorted correctly (im sorting by date), so what I tried was to call the sortGrid right after. That did work, but now the sort arrow is gone!
Here is my markup/code:
jQuery("#list").jqGrid({
url: '',
datatype: 'clientSide',
mtype: 'POST',
colNames: ['Id', 'Name', 'Desired Role', 'City', 'State', 'Last Modified'],
colModel: [
{ name: 'id', index: 'id', hidden: true },
{ name: 'fullname', index: 'fullname', width: 139 },
{ name: 'desiredrole', index: 'desiredrole', width: 235 },
{ name: 'city', index: 'city', width: 100 },
{ name: 'state', index: 'state', width: 50 },
{ name: 'lastmodifieddisplay', index: 'lastmodified', width: 100, align: 'right', }, ],
jsonReader: {
root: "profiles",
page: "curPage",
total: "totalPageCount",
records: "recordCount",
repeatitems: false
},
pager: jQuery('#pager'),
recordtext: 'profiles found',
rowNum: 10,
rowList: [],
sortname: 'lastmodifieddisplay',
sortorder: "desc",
viewrecords: true,
imgpath: '../../images/jqgrid',
caption: ''
});
..and on my button click event I call:
var mygrid = jQuery("#list")[0];
mygrid.addJSONData(result);
jQuery("#list").sortGrid('lastmodifieddisplay', true);
--- What is the matter here? Am I doing things correctly?
Thanks!
Thor.
02:31

Moderators
30/10/2007

Hello,
Use the sorttype property in colModel. Also refrer to docs.
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.
12:55

05/02/2009

I've scoured through documentation, but I cannot find the answer to this.
I've actually come across multiple docs online, which one is the best and up to date?
I added the sorttype property, nothing changed. I then changed the sort column to fullname (string). I get the same strange behavior.
1. Why doesn't the addJSONData method sort the grid based on the current grid setting?
2. In the docs it says that sortGrid sorts and shows the sort arrow appropriately. For me it is disappearing. Bug?
3. When I call sortGrid the little "Loading" message appear. So is it really loading anything or is the message perhaps misleading?
Any help would be appreciated.
Thanks,
Thor.
23:51

05/02/2009

Hi Tony,
I tried again tonight reading your documentation, and I then started reading your js code until I figured it out. What I should have been using is 'local' as datatype, not clientSide. Your documentation is unclear on when to use which, and it actually states:
"First we must instruct jqGrid that the data that will be present is at client side. This is done with the option datatype. To use this we must set
datatype : "clientSide"
The other option that can be used is "local" i.e. datatype: "local" These are the same."
However, when digging through your code, I can see that you treat these two quite differently - hence they are not the same! (Besides why would you have the two of them if they were exactly the same 🙂
Anyway, great job buddy on the grid, but the doc/help is sometimes a bit vague. I might have some more questions down the road if that's ok.
Thanks,
Thor.
03:19

Moderators
30/10/2007

Hello,
Could you please point me where is the difference to correct this? Thank you.
Also when you use the date sorting it is a good idea to use the datefmt option to thell the grid what is the format for the date to sort it in right way. The dafault option of datefmt is Y-m-d. Is this your format? If not you will have bad sorting.
Also this is described in the docs: Basic Grid -> Properties->colModel Properties
Best 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.
10:07

05/02/2009

Thanks for your reply Tony.
After looking again at the code, I might have misdiagnosed. Anyway, the main problem I´m having is that I don't want the grid to be sorting whenever I click the arrows or the header columns. The thing is, my data fetch takes care of sorting on the server. That way, sorting just those records that are visible on the client does not make any sense. (I still want to get the information from the grid which column the user clicked on, etc.) If there is any switch where I can turn it off, that would be great, otherwise I probably have to take your code and modify it a bit.
Thanks,
Thor.
10:16

05/02/2009

I just fixed this for me - in the populate method I only made the clientSide call the sortArrayData and the local doesnt do anything: (you had both call sort). If there is really no difference for these two in your code, you might want to have the local behave like this?
case "clientSide":
sortArrayData();
break;
case "local":
break;
10:32

Moderators
30/10/2007

Hello,
Thanks - it is really a bug. I fixed this. Also in the code I make comparations only for datatype local and not for clientSide.
Also to correct quick a bug here is the code:
case "local":
case "clientSide":
ts.p.datatype = "local";
sortArrayData();
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:
49 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