Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attribute sortType to support server-side (remote) sorting. #1911

Open
wants to merge 1 commit into
base: dev-master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions src/datatable/js/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
}
},
Expand All @@ -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;
}
}
}
},
Expand Down Expand Up @@ -454,7 +470,9 @@ Y.mix(Sortable.prototype, {

this._setSortBy();

this._initSortFn();
if (this.get('sortType') === 'local') {
this._initSortFn();
}

this._initSortStrings();

Expand Down Expand Up @@ -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.

Expand Down