Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#1825 closed defect (fixed)

Sorting of numbers in FilteringTable fails

Reported by: andi.hotz@… Owned by: Tom Trenka
Priority: high Milestone:
Component: Widgets Version: 0.4
Keywords: FilteringTable Sort Number Cc:
Blocked By: Blocking:

Description

In the FiliteringTable? (rev. 6404) the sorting is done with the function createSortFunction. Two values are compared. The values apear to be always of type string:

var a = self.store.getField(self.getDataByRow(rowA), field);
var b = self.store.getField(self.getDataByRow(rowB), field);
var ret = 0;
if(a > b) ret = 1;
if(a < b) ret = -1;

If a and b are numbers the sort order is only correct when they have the same number of digits. To verify this I tested a and b for their type and casted explicitly with the desired result.
If a test case is needed for this one I can provide one.

Change History (9)

comment:1 Changed 13 years ago by andi.hotz@…

On http://raum.sahits.ch/dojo/tests/widget/test_FilteringTable_numberSort.html the problem is shown. Curiously enough when I tried to add a numeric column in the original test the sorting was correct. So it might not be the sorting. Furthermore if you sort by the second to last column which is also numeric it works.
Solved it my self: The column name (field attribute) may not be 'Id' which clashes with the variable valueField.

comment:2 Changed 13 years ago by bill

Milestone: 0.6
Owner: changed from bill to Tom Trenka

Assigning to Tom (although from the bug description I'm not clear if this is a bug or a user error, or just a limitation that we won't fix)

comment:3 Changed 13 years ago by andi.hotz@…

Actually it is a user error. Though a confusing one. So at best I would call it an enhancement by either find a better default name for valueField (e.g. defaultId instead of Id) or some documentation about possible pitfalls concerning the naming.

comment:4 Changed 13 years ago by Tom Trenka

Resolution: invalid
Status: newclosed

Documentation is the solution here for sure; we've gotten to the point where some widgets are complex enough to where tutorials are needed that are easy to find (i.e. smacking them into the wiki is probably not enough in the long term).

btw, sorting works just fine because it relies on the data type of the underlying object field. If you were sure your fields are cast correctly, you should be good to go.

Closing this.

comment:5 Changed 13 years ago by guest

Resolution: invalid
Status: closedreopened

... But the fields are not being cast correctly (or should I say permanently).

During initial parsing, a dataType=Number valueField will get cast correctly. However, it always gets reset to a String object by way of the modifier code:

		var arr = this.store.getFromHtml(this.columns, body, function(obj, row){
			obj[self.valueField] = dojo.html.getAttribute(row, "value");
			if(dojo.html.getAttribute(row, "selected")=="true"){
				self["__selected__"].push(obj);
			}
		});

For parsed HTML tables, where the user specifies their own valueField, the value= attribue is actually redundant and should be ignored.

comment:6 Changed 13 years ago by Tom Trenka

Resolution: fixed
Status: reopenedclosed

(In [6458]) Fixes #1825.

comment:7 Changed 13 years ago by bill

Milestone: 0.60.5

comment:8 Changed 13 years ago by bill

Milestone: 0.50.4.1

comment:9 Changed 13 years ago by (none)

Milestone: 0.4.1

Milestone 0.4.1 deleted

Note: See TracTickets for help on using tickets.