PDA

View Full Version : Move sort functionality entirely into DataModel


kovtik
11-03-2006, 04:54 PM
It will be great to provide a capability to set sort type functions for every data model column in the data schema (like it was previously in the column schema), like this:
var dataSchema = {
tagName: 'child',
fields: ['name', 'date', 'size'],
sortTypes: [ , parseDate, parseInt]
}
var dataModel = new YAHOO.ext.grid.XMLDataModel(dataSchema);
I think also that
DefaultDataModel.sort(sortInfo, columnIndex, direction, suppressEvent)
function can be replaced by
DefaultDataModel.sort(sortInfo, dataColumnIndex, direction, suppressEvent)
This will provide a capability to sort all data columns and makes data model more independent, so it can be used only to load, parse and sort xml data, for example.
DefaultDataModel.setDefaultSort(sortInfo, columnIndex, direction) function can be moved into DefaultColumnModel class because it sets default sorting for only rendered columns.

I hope you understand my idea to separate data from view as much as possible.

jack.slocum
11-03-2006, 05:01 PM
I understand completely and I have wanted to do this for a while. The problem is it will break too much existing code.

In the latest beta download I have in fact changed it, but in a backwards compatible way. Take a look at the sort() method (the document on it was updated as well).

The first parameter can now be a column model, arbitrary object with getSortType function, a function pointer or null.

These is leading towards changes to the schema to support sortTypes on the data model schema as you suggested. I'm trying to make it incremental and backwards compatible.