From 15ca9d887c35209aae6626b5d4a7db9c836124a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20=C3=87AGDA=C5=9E?= Date: Wed, 29 Mar 2017 16:34:21 +0300 Subject: [PATCH] #1459: implement initial sorting direction --- dev/jquery.jtable.sorting.js | 8 ++++++-- jquery.jtable.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dev/jquery.jtable.sorting.js b/dev/jquery.jtable.sorting.js index b7e9fa57..a83d6248 100644 --- a/dev/jquery.jtable.sorting.js +++ b/dev/jquery.jtable.sorting.js @@ -57,7 +57,7 @@ _createHeaderCellForField: function (fieldName, field) { var $headerCell = base._createHeaderCellForField.apply(this, arguments); if (this.options.sorting && field.sorting) { - this._makeColumnSortable($headerCell, fieldName); + this._makeColumnSortable($headerCell, fieldName, field.initialSortingDirection); } return $headerCell; @@ -104,7 +104,7 @@ /* Makes a column sortable. *************************************************************************/ - _makeColumnSortable: function ($columnHeader, fieldName) { + _makeColumnSortable: function ($columnHeader, fieldName, initialSortingDirection) { var self = this; $columnHeader @@ -119,6 +119,10 @@ self._sortTableByColumn($columnHeader); }); + if(initialSortingDirection){ + $columnHeader.addClass('jtable-column-header-sorted-' + initialSortingDirection.toLowerCase()); + } + //Set default sorting $.each(this._lastSorting, function (sortIndex, sortField) { if (sortField.fieldName == fieldName) { diff --git a/jquery.jtable.js b/jquery.jtable.js index b07a50f3..320a8a4c 100644 --- a/jquery.jtable.js +++ b/jquery.jtable.js @@ -4256,7 +4256,7 @@ THE SOFTWARE. _createHeaderCellForField: function (fieldName, field) { var $headerCell = base._createHeaderCellForField.apply(this, arguments); if (this.options.sorting && field.sorting) { - this._makeColumnSortable($headerCell, fieldName); + this._makeColumnSortable($headerCell, fieldName, field.initialSortingDirection); } return $headerCell; @@ -4303,7 +4303,7 @@ THE SOFTWARE. /* Makes a column sortable. *************************************************************************/ - _makeColumnSortable: function ($columnHeader, fieldName) { + _makeColumnSortable: function ($columnHeader, fieldName, initialSortingDirection) { var self = this; $columnHeader @@ -4318,6 +4318,10 @@ THE SOFTWARE. self._sortTableByColumn($columnHeader); }); + if(initialSortingDirection){ + $columnHeader.addClass('jtable-column-header-sorted-' + initialSortingDirection.toLowerCase()); + } + //Set default sorting $.each(this._lastSorting, function (sortIndex, sortField) { if (sortField.fieldName == fieldName) {