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 date values with alternative display format
29/07/2008
14:34
Avatar
daviddlyman
daviddlyman
Member
Members
Forum Posts: 6
Member Since:
29/07/2008
sp_UserOfflineSmall Offline

Tony and all,

Great work on JQGrid! I have recently adopted JQuery and JQGrid (among other plug-ins) to replace Component Art and MSAJAX from our ASP.NET site (http://nutshellmail.com). Our code is getting cleaner and performance is definitely far better.

There is one limitation with JQGrid that I am hoping you can help me overcome. I have a date field in the grid that I want formatted as "ddd M/D h:mm TT" (i.e. "Tue 7/29 2:01 PM"). However, I also want this column to be sortable. Unfortunately, I am unsure if/how I can accomplish this goal.

I am currently using datatype: "local" and generating my own array from a JSON response. I already have the date format in milliseconds since Jan 1, 1970 and am passing it into the data array. I am then pointing the column index to that field, but still no luck.

ComponentArt and ExtJS Grid both support the ability tie a rendering function to each column (see the definition for Ext here).

Can you please suggest a way that I can display the date format as "Tue 7/29 2:01 PM" while still maintaining the ability to sort?

Thanks,

David

30/07/2008
06:11
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

David,

Thank you for this. One of the big difference between jqGrid and others is the speed. This property is at first place. But having this we do not have a ton of other properies that nobody will use. We have a methods for customising this - i.e with a little programing you can achieve this. I recommend you to use afterInsertRow event and setCell method. The only thinng that you should do is to write your own date formater. The code should something like this:

afterInsertRow : function(rowid, datarow) {

// here is the code to format your date something like

mynewdate = customfunc(datarow.mydate);

$(”#mygrid”).setCell(rowid,'mydate',mynewdate);

}

The clear solution here is that the date should be formated server side

Now about the sorting. Currently jqGrid support sorting of dates only if they are numbers. I think that this shuld be corrected and mybe will be done soon.

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.

30/07/2008
15:55
Avatar
daviddlyman
daviddlyman
Member
Members
Forum Posts: 6
Member Since:
29/07/2008
sp_UserOfflineSmall Offline

Tony,

Thanks for the tip on using afterInsertRow for applying a formatting function to my data.

The sorting issue is definitely the tougher one to overcome, although I am hoping it is not too bad. I think that the easiest solution is to allow the sort event for a given column to key off of the data in another column. In my case, I have created a hidden column with the date values as milliseconds. If I could tell the visible date column to sort based on the values of the hidden column instead of the values in the column I click, my problems would be solved.

Thanks,

David

31/07/2008
03:51
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

You can do that easy.

Use onSortCol (this event fires before sorting)

onSortCol : function (colname, colindex) {

if(colname == "visible_col") {

$("#mygrid").setGridParam({sortname:"hidden_col"});

//no need to use triger reloadgrid

}

}

The only missing part here is a sorting image

jqGrid is flexible Wink

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.

04/08/2008
10:47
Avatar
daviddlyman
daviddlyman
Member
Members
Forum Posts: 6
Member Since:
29/07/2008
sp_UserOfflineSmall Offline

Excellent! That seems to work perfectly. Thanks a million!

06/08/2008
02:28
Avatar
daviddlyman
daviddlyman
Member
Members
Forum Posts: 6
Member Since:
29/07/2008
sp_UserOfflineSmall Offline

Tony,

I spoke too soon. Your suggestion seemed to work, but I just realized that sorting was only functioning for certain cases where my displayed date values in the visible column are all the same year. Since I am not displaying year, I still cannot properly sort values from multiple years. The grid is correctly sorting by the hidden column at first, but not when I click the visible date column.

The SortArrayData() function for client-side data sets the column to be sorted based on ts.p.lastsort. In other words, it does not care about sortname. Do you have a suggestion for sorting a "local" dataset against the data in a column other than the one that is clicked?

Thanks,

David

06/08/2008
03:18
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Thanks David,

Fixed.

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.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
22 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