diff options
author | Halil İbrahim Kalkan <hikalkan@gmail.com> | 2013-01-13 20:47:06 +0200 |
---|---|---|
committer | Halil İbrahim Kalkan <hikalkan@gmail.com> | 2013-01-13 20:47:06 +0200 |
commit | 714e396500d8ca31ccf5e0972c8a77b365365f4a (patch) | |
tree | 43cae707262293df88553dd6433863a42be04d2a /dev/jquery.jtable.sorting.js | |
parent | a08e406f31de23ff7fd8cb766fdd9f7f62fbd82d (diff) | |
download | jtable-714e396500d8ca31ccf5e0972c8a77b365365f4a.zip jtable-714e396500d8ca31ccf5e0972c8a77b365365f4a.tar.gz jtable-714e396500d8ca31ccf5e0972c8a77b365365f4a.tar.bz2 |
jTable version 2.0.0
All codebase revised and refactored.
All CSS re-written using less css. [#3]
Added metro style theme with 10 color options. [#2]
Added a basic theme that can be start point who want to create themes to
jTable.
Added methods: getRowByKey, selectRows. [#8]
Added field option: ajaxSettings.
Added feature: editing primary key's value. [#34]
Added feature: Allow updating a record with server response after
updateAction [#66]
Added ready-to-use localization scripts. [#67]
Fixed some issues. [#25, #29, #42, #46]
Set default values for key field as "edit: false" and "create: false"
Fixed some other minor bugs.
Removed standard theme.
Tested with latest jQuery libraries (jQuery v1.8.3 and jQuery UI
v1.9.2).
Diffstat (limited to 'dev/jquery.jtable.sorting.js')
-rw-r--r-- | dev/jquery.jtable.sorting.js | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/dev/jquery.jtable.sorting.js b/dev/jquery.jtable.sorting.js new file mode 100644 index 0000000..d5b9300 --- /dev/null +++ b/dev/jquery.jtable.sorting.js @@ -0,0 +1,123 @@ +/************************************************************************
+* SORTING extension for jTable *
+*************************************************************************/
+(function ($) {
+
+ //Reference to base object members
+ var base = {
+ _create: $.hik.jtable.prototype._create,
+ _normalizeFieldOptions: $.hik.jtable.prototype._normalizeFieldOptions,
+ _createHeaderCellForField: $.hik.jtable.prototype._createHeaderCellForField,
+ _createRecordLoadUrl: $.hik.jtable.prototype._createRecordLoadUrl
+ };
+
+ //extension members
+ $.extend(true, $.hik.jtable.prototype, {
+
+ /************************************************************************
+ * DEFAULT OPTIONS / EVENTS *
+ *************************************************************************/
+ options: {
+ sorting: false,
+ defaultSorting: ''
+ },
+
+ /************************************************************************
+ * PRIVATE FIELDS *
+ *************************************************************************/
+
+ _lastSorting: '', //Last sorting of the table
+
+ /************************************************************************
+ * OVERRIDED METHODS *
+ *************************************************************************/
+
+ /* Overrides _normalizeFieldOptions method to normalize sorting option for fields.
+ *************************************************************************/
+ _normalizeFieldOptions: function (fieldName, props) {
+ base._normalizeFieldOptions.apply(this, arguments);
+ props.sorting = (props.sorting != false);
+ },
+
+ /* Overrides _createHeaderCellForField to make columns sortable.
+ *************************************************************************/
+ _createHeaderCellForField: function (fieldName, field) {
+ var $headerCell = base._createHeaderCellForField.apply(this, arguments);
+ if (this.options.sorting && field.sorting) {
+ this._makeColumnSortable($headerCell, fieldName);
+ }
+
+ return $headerCell;
+ },
+
+ /* Overrides _createRecordLoadUrl to add sorting specific info to URL.
+ *************************************************************************/
+ _createRecordLoadUrl: function () {
+ var loadUrl = base._createRecordLoadUrl.apply(this, arguments);
+ loadUrl = this._addSortingInfoToUrl(loadUrl);
+ return loadUrl;
+ },
+
+ /************************************************************************
+ * PRIVATE METHODS *
+ *************************************************************************/
+
+ /* Makes a column sortable.
+ *************************************************************************/
+ _makeColumnSortable: function ($columnHeader, fieldName) {
+ var self = this;
+ $columnHeader
+ .addClass('jtable-column-header-sortable')
+ .click(function(e) {
+ e.preventDefault();
+ self._sortTableByColumn($columnHeader);
+ });
+
+ //Default sorting?
+ if (self.options.defaultSorting.indexOf(fieldName) > -1) {
+ if (self.options.defaultSorting.indexOf(' DESC') > -1) {
+ $columnHeader.addClass('jtable-column-header-sorted-desc');
+ self._lastSorting = fieldName + " DESC";
+ } else {
+ $columnHeader.addClass('jtable-column-header-sorted-asc');
+ self._lastSorting = fieldName + " ASC";
+ }
+ }
+ },
+
+ /* Sorts table according to a column header.
+ *************************************************************************/
+ _sortTableByColumn: function ($columnHeader) {
+ //Remove sorting styles from all columns except this one
+ $columnHeader.siblings().removeClass('jtable-column-header-sorted-asc jtable-column-header-sorted-desc');
+
+ //Sort ASC or DESC according to current sorting state
+ if ($columnHeader.hasClass('jtable-column-header-sorted-asc')) {
+ $columnHeader
+ .removeClass('jtable-column-header-sorted-asc')
+ .addClass('jtable-column-header-sorted-desc');
+ this._lastSorting = $columnHeader.data('fieldName') + " DESC";
+ } else {
+ $columnHeader
+ .removeClass('jtable-column-header-sorted-desc')
+ .addClass('jtable-column-header-sorted-asc');
+ this._lastSorting = $columnHeader.data('fieldName') + " ASC";
+ }
+
+ //Load current page again
+ this._reloadTable();
+ },
+
+ /* Adds jtSorting parameter to a URL as query string.
+ *************************************************************************/
+ _addSortingInfoToUrl: function (url) {
+ if (!this.options.sorting || this._lastSorting == '') {
+ return url;
+ }
+
+ return (url + (url.indexOf('?') < 0 ? '?' : '&') + 'jtSorting=' + this._lastSorting);
+ }
+
+ });
+
+})(jQuery);
|