sort.js revision 32624ce45f113c04dfa5469b3cc77df42c4c46f4
/**
Adds support for column sort.
@module datatable-sort
**/
toArray = Y.Array,
dirMap = {
asc : 1,
desc: -1,
"1" : 1,
"-1": -1
};
function Sortable() {}
// Which columns in the UI should suggest and respond to sorting interaction
// pass an empty array if no UI columns should show sortable, but you want the
// table.sort(...) API
sortable: {
value: 'auto',
validator: '_validateSortable'
},
// Last sort params
sortBy: {
validator: '_validateSortBy',
getter: '_getSortBy'
},
strings: {
valueFn: function () {
}
}
};
}));
},
sortBy = [],
// To avoid updating column configs or sortBy directly
col = {};
}
if (columns) {
index = -1;
break;
}
}
}
} else {
break;
}
}
}
}
}));
},
//----------------------------------------------------------------------------
// Protected properties and methods
//----------------------------------------------------------------------------
_afterDataChange: function (e) {
// object values always trigger a change event, but we only want to
// call _initSortFn if the value passed to the `data` attribute was a
// new ModelList, not a set of new data as an array, or even the same
// ModelList.
this._initSortFn();
}
},
_afterSortByChange: function (e) {
// Can't use a setter because it's a chicken and egg problem. The columns
// need to be set up to translate, but columns are initialized from
// Core's initializer. So construction-time assignment would fail.
this._setSortBy();
// Don't sort unless sortBy has been set
if (!this.data.comparator) {
}
}
},
_bindSortUI: function () {
this._uiSetSortable);
if (this._theadNode) {
Y.rbind('_onUITriggerSort', this),
}
},
_defSortFn: function (e) {
},
destructor: function () {
if (this._sortHandle) {
this._sortHandle.detach();
}
},
// "sortBy." is 7 characters. Used to catch
// TODO: table.get('sortBy.asObject')? table.get('sortBy.json')?
if (detail === 'state') {
state = [];
});
}
// TODO: Always return an array?
} else {
return val;
}
},
initializer: function () {
this._parseSortable();
this._setSortBy();
this._initSortFn();
this.after({
});
this.publish('sort', {
});
},
_initSortFn: function () {
var self = this;
// TODO: This should be a ModelList extension.
// FIXME: Modifying a component of the host seems a little smelly
// FIXME: Declaring inline override to leverage closure vs
// binding the _compare implementation to this, resulting in an
// extra function hop during sorting. Lesser of three evils?
var cmp = 0,
} else {
// FIXME? Requires columns without sortFns to have key
}
}
return cmp;
};
// TODO: is this necessary? Should it be elsewhere?
} else {
// Leave the _compare method in place to avoid having to set it
// up again. Mistake?
delete this.data.comparator;
}
},
_onUITriggerSort: function (e) {
config = {},
dir = 1,
e.preventDefault();
// TODO: if (e.ctrlKey) { /* subsort */ }
if (id) {
// Flip current sortDir or default to 1 (asc)
}
});
if (column) {
this.fire('sort', {
originEvent: e,
});
}
}
},
_parseSortable: function () {
columns = [],
// isArray is called because arrays are objects, but will rely
// on getColumn to nullify them for the subsequent if (col)
}
if (col) {
}
}
} else if (sortable) {
if (sortable === 'auto') {
}
}
}
}
},
_renderSortable: function () {
this._uiSetSortable();
this._bindSortUI();
},
_setSortBy: function () {
var columns = this._displayColumns,
this._sortBy = [];
// Purge current sort state from column configs
// TODO: be more thorough
}
}
dir = 1;
// Have to use a for-in loop to process sort({ foo: -1 })
break;
}
}
}
if (name) {
// Allow sorting of any model field and any column
// FIXME: this isn't limited to model attributes, but there's no
// convenient way to get a list of the attributes for a Model
// subclass *including* the attributes of its superclasses.
if (column) {
}
}
}
}
},
_sortComparator: function (item) {
// Defer sorting to ModelList's _compare
return item;
},
_validateSortable: function (val) {
},
_uiSetSortable: function () {
this.getClassName('sortable'),
// TODO: this.head.render() + decorate cells?
if (node) {
}
}
}
}
},
_validateSortBy: function (val) {
return val === null ||
}
}, true);