diff --git a/src/datatable/js/sort.js b/src/datatable/js/sort.js index b73438d1aad..47176af2ae2 100644 --- a/src/datatable/js/sort.js +++ b/src/datatable/js/sort.js @@ -129,6 +129,19 @@ Sortable.ATTRS = { validator: '_validateSortable' }, + /** + The type of sorting being performed: local or remote + + @attribute sortType + @type {String} + @default "local" + @since 3.18.0 + **/ + sortType: { + value: 'local', + validator: '_validateSortType' + }, + /** The current sort configuration to maintain in the data. @@ -301,7 +314,7 @@ Y.mix(Sortable.prototype, { this._setSortBy(); // Don't sort unless sortBy has been set - if (this._sortBy.length) { + if (this._sortBy.length && this.get('sortType') === 'local') { if (!this.data.comparator) { this.data.comparator = this._sortComparator; } @@ -324,7 +337,8 @@ Y.mix(Sortable.prototype, { // 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. - if (e.prevVal !== e.newVal || e.newVal.hasOwnProperty('_compare')) { + if ((e.prevVal !== e.newVal || e.newVal.hasOwnProperty('_compare')) && + this.get('sortType') === 'local') { this._initSortFn(); } }, @@ -341,10 +355,12 @@ Y.mix(Sortable.prototype, { _afterSortRecordChange: function (e) { var i, len; - for (i = 0, len = this._sortBy.length; i < len; ++i) { - if (e.changed[this._sortBy[i].key]) { - this.data.sort(); - break; + if (this.get('sortType') === 'local') { + for (i = 0, len = this._sortBy.length; i < len; ++i) { + if (e.changed[this._sortBy[i].key]) { + this.data.sort(); + break; + } } } }, @@ -454,7 +470,9 @@ Y.mix(Sortable.prototype, { this._setSortBy(); - this._initSortFn(); + if (this.get('sortType') === 'local') { + this._initSortFn(); + } this._initSortStrings(); @@ -877,6 +895,19 @@ Y.mix(Sortable.prototype, { return val === 'auto' || isBoolean(val) || isArray(val); }, + /** + Allows values "local" or "remote" through. + + @method _validateSortable + @param {Any} val The input value to `set("sortType", VAL)` + @return {Boolean} + @protected + @since 3.18.0 + **/ + _validateSortType: function (val) { + return val === 'local' || val === 'remote'; + }, + /** Allows strings, arrays of strings, objects, or arrays of objects.