Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#535 closed defect (invalid)

improvement for SortableTable / sortusing

Reported by: janroth Owned by: Tom Trenka
Priority: high Milestone:
Component: General Version: 0.2
Keywords: SortableTable Cc:
Blocked By: Blocking:


Hi, when using the 'sortusing' in SortableTable?, the function named in sortusing doesn't get the value of field, which is needed to get the col, on which the sorting is done actually.

Instead of using:

var sort = col.sortFunction;

one should use:

var sort=function(a,b){

return col.sortFunction(a[field], b[field]);


Hope this helps,


Change History (6)

comment:1 Changed 16 years ago by Tom Trenka

Resolution: invalid
Status: newclosed

Closing this ticket...I think probably you didn't how this works. In the sortusing attribute, you use a function reference--not the result of a function. To take your example above, in the widget def, you'd say:

<td sortusing="sort">Custom sort</td>

where "sort" takes 2 arguments and returns 1, 0, or -1.

This does work correctly as written; it's just that it may be deceptive since it doesn't necessarily follow the typcial DOM 0 form.

comment:2 Changed 16 years ago by janroth

Resolution: invalid
severity: normalmajor
Status: closedreopened

Sorry, but I think you didn't get the point. I know about the function reference, and know how to use it, but when this function is actually called, the value of 'field' is undefined, so one doesn't know, what column to sort on, because the a and b given from the array's sort function are arrays...

Without the field variable given, the function, to which a reference is given in the sortusing attribute, can't decide on which collumn it has to sort.

Given my improvement, the sort-function gets the values of the fields to which field references (a[field]).

comment:3 Changed 16 years ago by anonymous

Owner: changed from anonymous to Tom Trenka
Status: reopenednew

comment:4 Changed 16 years ago by anonymous

Milestone: 0.3.1

comment:5 Changed 16 years ago by Tom Trenka

Resolution: invalid
Status: newclosed

Your sort function is responsible for accessing the field value; there are situations (which I ran across almost immediately) when adding this functionality. The sort function itself compares 2 data members (you're sorting on data objects, not fields).

The key here is that a function in sortUsing can use *any* of the fields (regardless of the column you're in) for comparison, making it much more flexible than if you just expected the fields. This may be an issue if you're trying to do some sort of dynamic sort (and determining which field to use at runtime) but my feeling was that this was a better behavior than locking the sort to the actual field.

Note also that you can use any type that's in the system, as long as it's sortable using standard stuff.

SO...the key here is that your sort function has access to ALL of the fields in each a and b object, not just the field of the column itself. (Frankly if you wanted just the fields, you wouldn't use sortUsing at all).

comment:6 Changed 15 years ago by (none)

Milestone: 0.3.1

Milestone 0.3.1 deleted

Note: See TracTickets for help on using tickets.