/*------------------------------------------------------------------------ - HTML Table Filter Generator Sorting Feature - TF Adapter v2.1 for WebFX Sortable Table 1.12 (Erik Arvidsson) - By Max Guglielmi (tablefilter.free.fr) - Licensed under the MIT License -------------------------------------------------------------------------- Copyright (c) 2009-2012 Max Guglielmi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------ - Changelog: 1.1 [30-09-09] When table is paged now the whole table is sorted and not only the current page 1.2 [05-12-09] Added on_before_sort and on_after_sort callback functions 1.3 [06-09-10] Added IP adresses sort 1.4 [22-01-11] Added DDMMMYYYY date format support 1.5 [20-02-11] Image folder and sort icon can now be set in configuration object 1.6 [06-08-11] Added on_sort_loaded callback function 1.7 [20-08-11] Added sort arrow css classes properties Added sort custom key property allowing custom sorts Added AddSortType public method 1.8 [25-09-11] Bug fix: sort did not take into account results per page changes 1.9 [03-03-12] Bug fix: custom value attribute value was read only by Firefox 2.0 [08-04-12] Bug fix: zebra rows background are no longer inverted after sort 2.1 [25-08-12] Bug fix: IE9 did not sort columns correctly ------------------------------------------------------------------------*/ TF.prototype.SetSortTable = function(){ var o = this; //TF object var f = o.fObj; //TF config object var isTFPaged = false; //edit .sort-arrow.descending / .sort-arrow.ascending in filtergrid.css to reflect any path change o.sortImgPath = f.sort_images_path != undefined ? f.sort_images_path : o.themesPath; o.sortImgBlank = f.sort_image_blank != undefined ? f.sort_image_blank : 'blank.png'; o.sortImgClassName = f.sort_image_class_name != undefined ? f.sort_image_class_name : 'sort-arrow'; o.sortImgAscClassName = f.sort_image_asc_class_name != undefined ? f.sort_image_asc_class_name : 'ascending'; o.sortImgDescClassName = f.sort_image_desc_class_name != undefined ? f.sort_image_desc_class_name : 'descending'; o.sortCustomKey = f.sort_custom_key != undefined ? f.sort_custom_key : '_sortKey'; //cell attribute storing custom key /*** TF additional events ***/ //additional paging events for alternating bg issue o.Evt._Paging.nextEvt = function(){ if(o.sorted && o.alternateBgs) o.Filter(); } o.Evt._Paging.prevEvt = o.Evt._Paging.nextEvt; o.Evt._Paging.firstEvt = o.Evt._Paging.nextEvt; o.Evt._Paging.lastEvt = o.Evt._Paging.nextEvt; o.Evt._OnSlcPagesChangeEvt = o.Evt._Paging.nextEvt; /*** ***/ /*** Extension events ***/ //callback invoked after sort is loaded and instanciated o.onSortLoaded = tf_IsFn(f.on_sort_loaded) ? f.on_sort_loaded : null; //callback invoked before table is sorted o.onBeforeSort = tf_IsFn(f.on_before_sort) ? f.on_before_sort : null; //callback invoked after table is sorted o.onAfterSort = tf_IsFn(f.on_after_sort) ? f.on_after_sort : null; /*** SortableTable ***/ //in case SortableTable class is missing (sortabletable.js) if((typeof SortableTable)=='undefined'){ return; } //overrides headerOnclick method in order to handle th SortableTable.prototype.headerOnclick = function (e) { if(!o.sort) return; // TF adaptation var el = e.target || e.srcElement; // find Header element while (el.tagName != 'TD' && el.tagName != 'TH') // TF adaptation el = el.parentNode; this.sort(SortableTable.msie ? SortableTable.getCellIndex(el) : el.cellIndex); }; //overrides getCellIndex IE returns wrong cellIndex when columns are hidden SortableTable.getCellIndex = function (oTd) { var cells = oTd.parentNode.cells, l = cells.length, i; for (i = 0; cells[i] != oTd && i < l; i++) ; return i; }; //overrides initHeader in order to handle filters row position SortableTable.prototype.initHeader = function (oSortTypes) { if (!this.tHead) return; this.headersRow = o.headersRow; // TF adaptation var cells = this.tHead.rows[this.headersRow].cells; // TF adaptation var doc = this.tHead.ownerDocument || this.tHead.document; this.sortTypes = oSortTypes || []; var l = cells.length; var img, c; for (var i = 0; i < l; i++) { c = cells[i]; if (this.sortTypes[i] != null && this.sortTypes[i] != 'None') { c.style.cursor = 'pointer'; img = tf_CreateElm('img',['src', o.sortImgPath + o.sortImgBlank]); c.appendChild(img); if (this.sortTypes[i] != null) c.setAttribute( '_sortType', this.sortTypes[i]); tf_AddEvent(c, 'click', this._headerOnclick); } else { c.setAttribute( '_sortType', oSortTypes[i] ); c._sortType = 'None'; } } this.updateHeaderArrows(); }; //overrides updateHeaderArrows in order to handle arrows SortableTable.prototype.updateHeaderArrows = function () { var cells, l, img; if(o.sortConfig.asyncSort && o.sortConfig.triggerIds!=null){//external headers var triggers = o.sortConfig.triggerIds; cells = [], l = triggers.length; for(var j=0; j val.length) val = '0'+val; vals[x] = val; } val = vals.join('.'); return val; } function sortIP(a,b){ var aa = ipAddress(a.value.tf_LCase()); var bb = ipAddress(b.value.tf_LCase()); if (aa==bb) return 0; else if (aa