datagrid sorting

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Post Reply
kevin11
Posts: 101
Joined: Thu Aug 11, 2011 5:02 pm

datagrid sorting

Post by kevin11 » Mon Oct 03, 2011 1:05 pm

Apologies if this already has a solution or has been posted elsewhere...

In datagrid sorting, one can already set up sort types as alphabetic or numeric, and one can choose between ascending and descending. However, it would be nice if there was a flag that could specify how null values are to be dealt with. That is, is a null value to be sorted as though it is less than 0 say, or infinity. Alphabetically, a null could be specified as coming before A or after Z.

This issue has a visual impact on tables. If I have a column with alphabetic entries in it, and a bunch of nulls, then an ascending sort lists the null entries first and then the populated entries. That makes the top of the column blank and pushes all the real values to the bottom. Not too friendly that. A descending sort of course starts the column with the Z entries, but I suspect a user (well, me anyway) would prefer the ascending sort to list the A,B,C first, followed by blanks, and a descending to switch the Z,Y,X. The latter happens now, the former doesn't.

A work around is to trap the entries with a default column behaviour perhaps - replace nulls with some character that comes after Z for an ascending sort. The column ascending sort would then list A,B,C, etc, and the nulls go to the bottom of the column, where they are trapped and replaced with nulls again.

However, although there is a work around, it would be much nicer if there was a :

set the dgColumnSortNull [COLUMN] to "first" or "last"

which specifies where nulls come in an ascending sort.

Unless I'm missing something ????

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: datagrid sorting

Post by dunbarx » Mon Oct 03, 2011 11:35 pm

I will answer this in a very old fashioned way, since I do not know if there is some native or semi-native solution.

Write a simple function that does what you wish (you already pretty much already did this). Do it once and bank it; problem solved.

You can even name it: function dgColumnSortNull tColumn,tFirst

Craig Newman

kevin11
Posts: 101
Joined: Thu Aug 11, 2011 5:02 pm

Re: datagrid sorting

Post by kevin11 » Tue Oct 04, 2011 9:57 am

Hi Craig,

True, one can of course do it as a function, as I have, but surely the point of Feature Requests is to suggest possible improvements to LC which may be of benefit to other users. After all, the datagrid contains a sort algorithm, it could do with an extra property / flag that would improve it, particularly as the issue of sorting a datset containing null values is a common problem - indeed, a Google search on "null sort" gives half a million results. Some solutions are already embedded in other environments, or at least provide options of handling nulls. It seemed to me that LC, rather than having what appears to be a rather simple sort algorithm embedded in the datagrid, could provide a useful expansion which I am sure would assist other users.

and don't get me started on LC and date sorting....;)

Post Reply