Opened 13 years ago

Closed 13 years ago

#2220 closed defect (wontfix)

FilteringTable: allow custom sorting functions to operate on source data

Reported by: shaneosullivan1@… Owned by: Tom Trenka
Priority: high Milestone: 0.9
Component: Dojox Version: 0.4.1
Keywords: Cc:
Blocked By: Blocking:

Description

Currently the FilteringTable? only allows custom sorting functions to sort based on the raw values displayed visually in the table. However, in certain circumstances it is preferable to sort based on the original data added to the store. This would enable a developer to use metadata to augment the sorting process.

This could be made possible in three lines of code, one new and two changed, with no effect on existing users of the widget. Add a new custom attribute, e.g. called "sortWithData", defaulting to the value "false". Then, in the createSorter.createSortFunction function, change these two lines:

var a = self.store.getField(self.getDataByRow(rowA), field); var b = self.store.getField(self.getDataByRow(rowB), field); to

var a = meta.sortFunction && self.sortWithData ? self.getDataByRow(rowA) : self.store.getField(self.getDataByRow(rowA), field); var b = meta.sortFunction && self.sortWithData ? self.getDataByRow(rowB) : self.store.getField(self.getDataByRow(rowB), field);

Change History (5)

comment:1 Changed 13 years ago by shaneosullivan1@…

Another option that could be added would be to allow the user to sort based on the DOM rows. This would allow devs to sort on the visible data, metadata stored in the Store object, or on custom attributes set on the <tr> and <td> elements.

In this case, the createSortFunction could become the code below. It is more verbose, but would make the sorting algorithm much more flexible.

function createSortFunction(fieldIndex, dir){
	var meta=self.columns[fieldIndex];
	var field=meta.getField();
	var getValue = null;
	if(meta.sortFunction){
		if(self.sortWithDom){
			return function(rowA, rowB){
				if(dojo.html.hasAttribute(rowA,"emptyRow")){ return 1; }
				if(dojo.html.hasAttribute(rowB,"emptyRow")){ return -1; }
				return meta.sortFunction(rowA,rowB);
			}
		}else if(self.sortWithData){
			getValue = function(row){
				return self.getDataByRow(row);	
			}
		}
	}
	if(!getValue){
		getValue = function(row){
			return self.store.getField(self.getDataByRow(row), field);
		}
	}
	return function(rowA, rowB){
		if(dojo.html.hasAttribute(rowA,"emptyRow")){ return 1; }
		if(dojo.html.hasAttribute(rowB,"emptyRow")){ return -1; }

		var a = getValue(rowA);
		var b = getValue(rowB);
		if(meta.sortFunction!=null){
			var ret = meta.sortFunction(a, b);
		} else {
			var ret = 0;
			if(a > b) ret = 1;
			if(a < b) ret = -1;
		}
		return dir * ret;
	}
}

comment:2 Changed 13 years ago by Tom Trenka

Owner: changed from bill to Tom Trenka

comment:3 Changed 13 years ago by dylan

Milestone: 0.9

comment:4 Changed 13 years ago by Adam Peller

Component: WidgetsDojox

comment:5 Changed 13 years ago by Tom Trenka

Resolution: wontfix
Status: newclosed

FilteringTable? is not being ported to either Dijit or DojoX, so I'm closing the bug.

Note: See TracTickets for help on using tickets.