Apply sortOrder if it is set in initialization

This commit is contained in:
Faris Ansari 2018-07-05 14:17:55 +05:30
parent cab9fff5e6
commit c49bc20f99
4 changed files with 12 additions and 2 deletions

View File

@ -53,7 +53,7 @@
{ name: "Name" },
{ name: "Position" },
{ name: "Office" },
{ name: "Extn." },
{ name: "Extn.", sortOrder: "desc" },
{ name: "Start Date" },
{ name: "Salary" }
];

View File

@ -273,6 +273,16 @@ export default class ColumnManager {
$.on(this.header, 'keydown', '.dt-filter', debounce(handler, 300));
}
applyDefaultSortOrder() {
// sort rows if any 1 column has a default sortOrder set
const columnsToSort = this.getColumns().filter(col => col.sortOrder !== 'none');
if (columnsToSort.length === 1) {
const column = columnsToSort[0];
this.sortColumn(column.colIndex, column.sortOrder);
}
}
sortRows(colIndex, sortOrder) {
return this.datamanager.sortRows(colIndex, sortOrder);
}

View File

@ -32,7 +32,6 @@ export default class DataManager {
this.prepareRows();
this.prepareTreeRows();
this.prepareRowView();
this.prepareNumericColumns();
}

View File

@ -34,6 +34,7 @@ class DataTable {
if (this.options.data) {
this.refresh();
this.columnmanager.applyDefaultSortOrder();
}
}