/** * tablefilter v0.2.0 by Max Guglielmi * build date: 2016-03-16T07:04:47.758Z * MIT License */ webpackJsonp([1],{27:function(e,t,n){function r(e){return n(s(e))}function s(e){return i[e]||function(){throw new Error("Cannot find module '"+e+"'.")}()}var i={"./array":16,"./array.js":16,"./cookie":9,"./cookie.js":9,"./date":5,"./date.js":5,"./dom":2,"./dom.js":2,"./emitter":7,"./emitter.js":7,"./event":1,"./event.js":1,"./extensions/advancedGrid/adapterEzEditTable":28,"./extensions/advancedGrid/adapterEzEditTable.js":28,"./extensions/advancedGrid/advancedGrid":29,"./extensions/advancedGrid/advancedGrid.js":29,"./extensions/colOps/colOps":30,"./extensions/colOps/colOps.js":30,"./extensions/colsVisibility/colsVisibility":31,"./extensions/colsVisibility/colsVisibility.js":31,"./extensions/filtersVisibility/filtersVisibility":32,"./extensions/filtersVisibility/filtersVisibility.js":32,"./extensions/sort/adapterSortabletable":33,"./extensions/sort/adapterSortabletable.js":33,"./extensions/sort/sort":34,"./extensions/sort/sort.js":34,"./helpers":6,"./helpers.js":6,"./modules/alternateRows":24,"./modules/alternateRows.js":24,"./modules/checkList":18,"./modules/checkList.js":18,"./modules/clearButton":22,"./modules/clearButton.js":22,"./modules/dropdown":15,"./modules/dropdown.js":15,"./modules/feature":11,"./modules/feature.js":11,"./modules/gridLayout":10,"./modules/gridLayout.js":10,"./modules/help":23,"./modules/help.js":23,"./modules/highlightKeywords":13,"./modules/highlightKeywords.js":13,"./modules/loader":12,"./modules/loader.js":12,"./modules/noResults":25,"./modules/noResults.js":25,"./modules/paging":21,"./modules/paging.js":21,"./modules/popupFilter":14,"./modules/popupFilter.js":14,"./modules/rowsCounter":19,"./modules/rowsCounter.js":19,"./modules/stateful":26,"./modules/stateful.js":26,"./modules/statusBar":20,"./modules/statusBar.js":20,"./modules/store":8,"./modules/store.js":8,"./sort":17,"./sort.js":17,"./string":3,"./string.js":3,"./types":4,"./types.js":4};r.keys=function(){return Object.keys(i)},r.resolve=s,e.exports=r,r.id=27},28:function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n0&&!n.startRow?void 0:n.startRow||t.refRow,n.base_path=n.base_path||t.basePath+"ezEditTable/";var s=n.editable,i=n.selection;i&&(n.default_selection=n.default_selection||"row"),n.active_cell_css=n.active_cell_css||"ezETSelectedCell";var l=0,a=0;if(i){var d=function(e,n,r){var s=e.Selection,i=function(r){if("row"===e.defaultSelection)s.SelectRowByIndex(r);else{e.ClearSelections();var i=n.cellIndex,l=t.tbl.rows[r];"both"===e.defaultSelection&&s.SelectRowByIndex(r),l&&s.SelectCell(l.cells[i])}if(t.validRowsIndex.length!==t.getRowsNb()){var o=t.tbl.rows[r];o&&o.scrollIntoView(!1),h&&(h.cellIndex===t.getCellsNb()-1&&t.gridLayout?t.tblCont.scrollLeft=1e8:0===h.cellIndex&&t.gridLayout?t.tblCont.scrollLeft=0:h.scrollIntoView(!1))}};if(t.validRowsIndex){var o,d=t.validRowsIndex,u=d.length,c="row"!==e.defaultSelection?n.parentNode:n,h="TD"===n.nodeName?n:null,f=void 0!==r?e.Event.GetKey(r):0,p=-1!==d.indexOf(c.rowIndex),b=t.feature("paging"),m=34===f||33===f?b&&b.pagingLength||e.nbRowsPerPage:1;if(p)34!==f&&33!==f?(l=d.indexOf(c.rowIndex),a=c.rowIndex):(o=34===f?u-1>=l+m?d[l+m]:[u-1]:l-m<=d[0]?d[0]:d[l-m],a=o,l=d.indexOf(o),i(o));else{if(c.rowIndex>a)if(c.rowIndex>=d[u-1])o=d[u-1];else{var g=l+m;o=g>u-1?d[u-1]:d[g]}else if(c.rowIndex<=d[0])o=d[0];else{var y=d[l-m];o=y?y:d[0]}a=c.rowIndex,i(o)}}},u=function(e,n){var r="row"!==e.defaultSelection?n.parentNode:n;if(t.paging&&t.feature("paging").nbPages>1){var s=t.feature("paging");e.nbRowsPerPage=s.pagingLength;var i=t.validRowsIndex,l=i.length,o=parseInt(s.startPagingRow,10)+parseInt(s.pagingLength,10),a=r.rowIndex;a===i[l-1]&&s.currentPageNb!==s.nbPages?s.setPage("last"):a==i[0]&&1!==s.currentPageNb?s.setPage("first"):a>i[o-1]&&ai[0]&&s.setPage("previous")}};if(t.paging&&(t.feature("paging").onAfterChangePage=function(e){var t=e.tf.extension("advancedGrid"),n=t._ezEditTable,r=n.Selection,s=r.GetActiveRow();s&&s.scrollIntoView(!1);var i=r.GetActiveCell();i&&i.scrollIntoView(!1)}),"row"===n.default_selection){var c=n.on_before_selected_row;n.on_before_selected_row=function(){u(arguments[0],arguments[1],arguments[2]),c&&c.call(null,arguments[0],arguments[1],arguments[2])};var h=n.on_after_selected_row;n.on_after_selected_row=function(){d(arguments[0],arguments[1],arguments[2]),h&&h.call(null,arguments[0],arguments[1],arguments[2])}}else{var f=n.on_before_selected_cell;n.on_before_selected_cell=function(){u(arguments[0],arguments[1],arguments[2]),f&&f.call(null,arguments[0],arguments[1],arguments[2])};var p=n.on_after_selected_cell;n.on_after_selected_cell=function(){d(arguments[0],arguments[1],arguments[2]),p&&p.call(null,arguments[0],arguments[1],arguments[2])}}}if(s){var b=n.on_added_dom_row;if(n.on_added_dom_row=function(){t.nbFilterableRows++,t.paging?(t.nbRows++,t.nbVisibleRows++,t.nbFilterableRows++,t.paging=!1,t.feature("paging").destroy(),t.feature("paging").reset()):t.emitter.emit("rows-changed",t,this),t.alternateRows&&t.feature("alternateRows").init(),b&&b.call(null,arguments[0],arguments[1],arguments[2])},n.actions&&n.actions["delete"]){var m=n.actions["delete"].on_after_submit;n.actions["delete"].on_after_submit=function(){t.nbFilterableRows--,t.paging?(t.nbRows--,t.nbVisibleRows--,t.nbFilterableRows--,t.paging=!1,t.feature("paging").destroy(),t.feature("paging").reset(!1)):t.emitter.emit("rows-changed",t,this),t.alternateRows&&t.feature("alternateRows").init(),m&&m.call(null,arguments[0],arguments[1])}}}try{this._ezEditTable=new EditTable(t.id,n,e),this._ezEditTable.Init()}catch(g){throw new Error(this.err)}this.initialized=!0}},{key:"reset",value:function(){var e=this._ezEditTable;e&&(this.cfg.selection&&e.Selection.Set(),this.cfg.editable&&e.Editable.Set())}},{key:"toggle",value:function(){var e=this._ezEditTable;e.editable?e.Editable.Remove():e.Editable.Set(),e.selection?e.Selection.Remove():e.Selection.Set()}},{key:"_toggleForInputFilter",value:function(){var e=this.tf;if(e.activeFlt){var t=e.activeFlt.getAttribute("ct"),n=e.getFilterType(t);n===e.fltTypeInp&&this.toggle()}}},{key:"destroy",value:function(){var e=this,t=this._ezEditTable;t&&(this.cfg.selection&&(t.Selection.ClearSelections(),t.Selection.Remove()),this.cfg.editable&&t.Editable.Remove()),this.emitter.off(["filter-focus","filter-blur"],function(){return e._toggleForInputFilter()}),this.initialized=!1}}]),e}();t["default"]=a},29:function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var s=n(28),i=r(s);t["default"]=i["default"]},30:function(module,exports,__webpack_require__){"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},_createClass=function(){function e(e,t){for(var n=0;n=jj;jj++)ucolIndex[jj]===colIndex[ii]&&(saved=1);0===saved&&(ucolMax++,ucolIndex[ucolMax]=colIndex[ii])}if("object"==_string2["default"].lower("undefined"==typeof labelId?"undefined":_typeof(labelId))&&"object"==_string2["default"].lower("undefined"==typeof colIndex?"undefined":_typeof(colIndex))&&"object"==_string2["default"].lower("undefined"==typeof operation?"undefined":_typeof(operation)))for(var rows=tf.tbl.rows,colvalues=[],ucol=0;ucolMax>=ucol;ucol++){colvalues.push(tf.getColValues(ucolIndex[ucol],!1,!0,excludeRow));for(var result,nbvalues=0,temp,meanValue=0,sumValue=0,minValue=null,maxValue=null,q1Value=null,medValue=null,q3Value=null,meanFlag=0,sumFlag=0,minFlag=0,maxFlag=0,q1Flag=0,medFlag=0,q3Flag=0,theList=[],opsThisCol=[],decThisCol=[],labThisCol=[],oTypeThisCol=[],mThisCol=-1,k=0;kmaxValue?parseFloat(cvalue):maxValue))}if(1===meanFlag&&(meanValue=sumValue/nbvalues),1===medFlag){var aux=0;nbvalues%2===1?(aux=Math.floor(nbvalues/2),medValue=theList[aux]):medValue=(theList[nbvalues/2]+theList[nbvalues/2-1])/2}var posa;if(1===q1Flag&&(posa=0,posa=Math.floor(nbvalues/4),q1Value=4*posa==nbvalues?(theList[posa-1]+theList[posa])/2:theList[posa]),1===q3Flag){posa=0;var posb=0;posa=Math.floor(nbvalues/4),4*posa===nbvalues?(posb=3*posa,q3Value=(theList[posb]+theList[posb-1])/2):q3Value=theList[nbvalues-posa-1]}for(var i=0;mThisCol>=i;i++){switch(opsThisCol[i]){case"mean":result=meanValue;break;case"sum":result=sumValue;break;case"min":result=minValue;break;case"max":result=maxValue;break;case"median":result=medValue;break;case"q1":result=q1Value;break;case"q3":result=q3Value}var precision=isNaN(decThisCol[i])?2:decThisCol[i];if(oTypeThisCol&&result){if(result=result.toFixed(precision),_dom2["default"].id(labThisCol[i]))switch(_string2["default"].lower(oTypeThisCol)){case"innerhtml":isNaN(result)||!isFinite(result)||0===nbvalues?_dom2["default"].id(labThisCol[i]).innerHTML=".":_dom2["default"].id(labThisCol[i]).innerHTML=result;break;case"setvalue":_dom2["default"].id(labThisCol[i]).value=result;break;case"createtextnode":var oldnode=_dom2["default"].id(labThisCol[i]).firstChild,txtnode=_dom2["default"].text(result);_dom2["default"].id(labThisCol[i]).replaceChild(txtnode,oldnode)}}else try{isNaN(result)||!isFinite(result)||0===nbvalues?_dom2["default"].id(labThisCol[i]).innerHTML=".":_dom2["default"].id(labThisCol[i]).innerHTML=result.toFixed(precision)}catch(e){}}var totRow=totRowIndex&&totRowIndex[ucol]?rows[totRowIndex[ucol]]:null;totRow&&(totRow.style.display="")}this.onAfterOperation&&this.onAfterOperation.call(null,tf)}}},{key:"destroy",value:function(){var e=this;this.tf.emitter.off(["after-filtering"],function(){return e.calc()})}}]),ColOps}();exports["default"]=ColOps},31:function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n0,this.onLoaded=d["default"].isFn(n.on_loaded)?n.on_loaded:null,this.onBeforeOpen=d["default"].isFn(n.on_before_open)?n.on_before_open:null,this.onAfterOpen=d["default"].isFn(n.on_after_open)?n.on_after_open:null,this.onBeforeClose=d["default"].isFn(n.on_before_close)?n.on_before_close:null,this.onAfterClose=d["default"].isFn(n.on_after_close)?n.on_after_close:null,this.onBeforeColHidden=d["default"].isFn(n.on_before_col_hidden)?n.on_before_col_hidden:null,this.onAfterColHidden=d["default"].isFn(n.on_after_col_hidden)?n.on_after_col_hidden:null,this.onBeforeColDisplayed=d["default"].isFn(n.on_before_col_displayed)?n.on_before_col_displayed:null,this.onAfterColDisplayed=d["default"].isFn(n.on_after_col_displayed)?n.on_after_col_displayed:null,t.gridLayout&&(this.headersTbl=t.feature("gridLayout").headTbl,this.headersIndex=0,this.onAfterColDisplayed=function(){},this.onAfterColHidden=function(){}),t["import"](n.name+"Style",t.stylePath+this.stylesheet,null,"link"),this.tf=t}return i(e,[{key:"toggle",value:function(){var e=this.contEl.style.display,t=this.onBeforeOpen,n=this.onBeforeClose,r=this.onAfterOpen,s=this.onAfterClose;t&&"inline"!==e&&t.call(null,this),n&&"inline"===e&&n.call(null,this),this.contEl.style.display="inline"===e?"none":"inline",r&&"inline"!==e&&r.call(null,this),s&&"inline"===e&&s.call(null,this)}},{key:"checkItem",value:function(e){var t=e.parentNode;if(t&&e){var n=e.firstChild.checked,r=e.firstChild.getAttribute("id").split("_")[1];r=parseInt(r,10),n?o["default"].addClass(t,this.listSlcItemCssClass):o["default"].removeClass(t,this.listSlcItemCssClass);var s=!1;(this.tickToHide&&n||!this.tickToHide&&!n)&&(s=!0),this.setHidden(r,s)}}},{key:"init",value:function(){this.manager&&(this.buildBtn(),this.buildManager(),this.initialized=!0)}},{key:"buildBtn",value:function(){var e=this;if(!this.btnEl){var t=this.tf,n=o["default"].create("span",["id",this.prfx+t.id]);n.className=this.spanCssClass,this.btnTgtId||t.setToolbar();var r=this.btnTgtId?o["default"].id(this.btnTgtId):t.rDiv;if(this.btnTgtId)r.appendChild(n);else{var s=r.firstChild;s.parentNode.insertBefore(n,s)}if(this.btnHtml){n.innerHTML=this.btnHtml;var i=n.firstChild;this.enableHover?c["default"].add(i,"mouseover",function(t){e.toggle(t)}):c["default"].add(i,"click",function(t){e.toggle(t)})}else{var l=o["default"].create("a",["href","javascript:;"]);l.className=this.btnCssClass,l.title=this.desc,l.innerHTML=this.btnText,n.appendChild(l),this.enableHover?c["default"].add(l,"mouseover",function(t){e.toggle(t)}):c["default"].add(l,"click",function(t){e.toggle(t)})}this.spanEl=n,this.btnEl=this.spanEl.firstChild,this.onLoaded&&this.onLoaded.call(null,this)}}},{key:"buildManager",value:function(){var e=this,t=this.tf,n=this.contElTgtId?o["default"].id(this.contElTgtId):o["default"].create("div",["id",this.prfxCont+t.id]);n.className=this.contCssClass;var r=o["default"].create("p");r.innerHTML=this.text,n.appendChild(r);var s=o["default"].create("ul",["id","ul"+this.name+"_"+t.id]);s.className=this.listCssClass;var i=this.headersTbl?this.headersTbl:t.tbl,l=this.headersTbl?this.headersIndex:t.getHeadersRowIndex(),a=i.rows[l];if(this.enableTickAll){var d=o["default"].createCheckItem("col__"+t.id,this.tickAllText,this.tickAllText);o["default"].addClass(d,this.listItemCssClass),s.appendChild(d),d.check.checked=!this.tickToHide,c["default"].add(d.check,"click",function(){for(var e=0;e',this.icnCollapseHtml='Collapse filters',this.defaultText="Toggle filters",this.targetId=n.target_id||null,this.enableIcon=n.enable_icon===!1?!1:!0,this.btnText=n.btn_text||"",this.collapseBtnHtml=this.enableIcon?this.icnCollapseHtml+this.btnText:this.btnText||this.defaultText,this.expandBtnHtml=this.enableIcon?this.icnExpandHtml+this.btnText:this.btnText||this.defaultText,this.btnHtml=n.btn_html||null,this.btnCssClass=n.btn_css_class||"btnExpClpFlt",this.contCssClass=n.cont_css_class||"expClpFlt",this.filtersRowIndex=d["default"].isUndef(n.filters_row_index)?t.getFiltersRowIndex():n.filters_row_index,this.visibleAtStart=d["default"].isUndef(n.visible_at_start)?!0:Boolean(n.visible_at_start),this.prfx="fltsVis_",this.onBeforeShow=d["default"].isFn(n.on_before_show)?n.on_before_show:null,this.onAfterShow=d["default"].isFn(n.on_after_show)?n.on_after_show:null,this.onBeforeHide=d["default"].isFn(n.on_before_hide)?n.on_before_hide:null,this.onAfterHide=d["default"].isFn(n.on_after_hide)?n.on_after_hide:null,t["import"](n.name+"Style",t.stylePath+this.stylesheet,null,"link"),this.tf=t}return i(e,[{key:"init",value:function(){this.initialized||(this.buildUI(),this.initialized=!0)}},{key:"buildUI",value:function(){var e=this,t=this.tf,n=o["default"].create("span",["id",this.prfx+t.id]);n.className=this.contCssClass,this.targetId||t.setToolbar();var r=this.targetId?o["default"].id(this.targetId):t.rDiv;if(this.targetId)r.appendChild(n);else{var s=r.firstChild;s.parentNode.insertBefore(n,s)}var i=void 0;this.btnHtml?(n.innerHTML=this.btnHtml,i=n.firstChild):(i=o["default"].create("a",["href","javascript:void(0);"]),i.className=this.btnCssClass,i.title=this.btnText||this.defaultText,i.innerHTML=this.collapseBtnHtml,n.appendChild(i)),c["default"].add(i,"click",function(){return e.toggle()}),this.contEl=n,this.btnEl=i,this.visibleAtStart||this.toggle()}},{key:"toggle",value:function(){var e=this.tf,t=e.gridLayout?e.feature("gridLayout").headTbl:e.tbl,n=t.rows[this.filtersRowIndex],r=n.style.display;this.onBeforeShow&&""!==r&&this.onBeforeShow.call(this,this),this.onBeforeHide&&""===r&&this.onBeforeHide.call(null,this),n.style.display=""===r?"none":"",this.enableIcon&&!this.btnHtml&&(this.btnEl.innerHTML=""===r?this.expandBtnHtml:this.collapseBtnHtml),this.onAfterShow&&""!==r&&this.onAfterShow.call(null,this),this.onAfterHide&&""===r&&this.onAfterHide.call(null,this)}},{key:"destroy",value:function(){(this.btnEl||this.contEl)&&(this.btnEl.innerHTML="",o["default"].remove(this.btnEl),this.btnEl=null,this.contEl.innerHTML="",o["default"].remove(this.contEl),this.contEl=null,this.initialized=!1)}}]),e}();t["default"]=h},33:function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e){return S["default"].removeNbFormat(e,"us")}function l(e){return S["default"].removeNbFormat(e,"eu")}function o(e,t){return C["default"].format(e,t)}function a(e){return o(e,"DMY")}function d(e){return o(e,"MDY")}function u(e){return o(e,"YMD")}function c(e){return o(e,"DDMMMYYYY")}function h(e){var t=e.split(".");for(var n in t){for(var r=t[n];3>r.length;)r="0"+r;t[n]=r}return t.join(".")}function f(e,t){var n=h(e.value.toLowerCase()),r=h(t.value.toLowerCase());return n==r?0:r>n?-1:1}Object.defineProperty(t,"__esModule",{value:!0});var p=function(){function e(e,t){for(var n=0;nr;r++);return r},SortableTable.prototype.initHeader=function(n){var r=this;if(!r.tHead){if(!t.gridLayout)return;r.tHead=t.feature("gridLayout").headTbl.tHead}r.headersRow=t.headersRow;var s=r.tHead.rows[r.headersRow].cells;r.sortTypes=n||[];for(var i=s.length,l=void 0,o=void 0,a=0;i>a;a++)o=s[a],null!==r.sortTypes[a]&&"None"!==r.sortTypes[a]?(o.style.cursor="pointer",l=y["default"].create("img",["src",e.imgPath+e.imgBlank]),o.appendChild(l),null!==r.sortTypes[a]&&o.setAttribute("_sortType",r.sortTypes[a]),T["default"].add(o,"click",r._headerOnclick)):(o.setAttribute("_sortType",n[a]),o._sortType="None");r.updateHeaderArrows()},SortableTable.prototype.updateHeaderArrows=function(){var t=this,n=void 0,r=void 0,s=void 0;if(e.asyncSort&&e.triggerIds.length>0){var i=e.triggerIds;n=[],r=i.length;for(var l=0;lo;o++){var a=n[o].getAttribute("_sortType");null!==a&&"None"!==a&&(s=n[o].lastChild||n[o],"img"!==s.nodeName.toLowerCase()&&(s=y["default"].create("img",["src",e.imgPath+e.imgBlank]),n[o].appendChild(s)),o===t.sortColumn?s.className=e.imgClassName+" "+(this.descending?e.imgDescClassName:e.imgAscClassName):s.className=e.imgClassName)}},SortableTable.prototype.getRowValue=function(e,t,n){var r=this,s=r._sortTypeInfo[t];if(s&&s.getRowValue)return s.getRowValue(e,n);var i=e.cells[n],l=SortableTable.getInnerText(i);return r.getValueFromString(l,t)},SortableTable.getInnerText=function(t){return t?t.getAttribute(e.customKey)?t.getAttribute(e.customKey):y["default"].getText(t):void 0}}},{key:"addSortType",value:function(){var e=arguments;SortableTable.prototype.addSortType(e[0],e[1],e[2],e[3])}},{key:"setSortTypes",value:function(){for(var e=this,t=this.tf,n=this.sortTypes,r=[],s=0;s0&&!function(){for(var t=e.triggerIds,n=0;n descending, false -> ascending\r\nSortableTable.prototype.defaultDescending = false;\r\n\r\n// shared between all instances. This is intentional to allow external files\r\n// to modify the prototype\r\nSortableTable.prototype._sortTypeInfo = {};\r\n\r\nSortableTable.prototype.setTable = function (oTable) {\r\n if ( this.tHead )\r\n this.uninitHeader();\r\n this.element = oTable;\r\n this.setTHead( oTable.tHead );\r\n this.setTBody( oTable.tBodies[0] );\r\n};\r\n\r\nSortableTable.prototype.setTHead = function (oTHead) {\r\n if (this.tHead && this.tHead != oTHead )\r\n this.uninitHeader();\r\n this.tHead = oTHead;\r\n this.initHeader( this.sortTypes );\r\n};\r\n\r\nSortableTable.prototype.setTBody = function (oTBody) {\r\n this.tBody = oTBody;\r\n};\r\n\r\nSortableTable.prototype.setSortTypes = function ( oSortTypes ) {\r\n if ( this.tHead )\r\n this.uninitHeader();\r\n this.sortTypes = oSortTypes || [];\r\n if ( this.tHead )\r\n this.initHeader( this.sortTypes );\r\n};\r\n\r\n// adds arrow containers and events\r\n// also binds sort type to the header cells so that reordering columns does\r\n// not break the sort types\r\nSortableTable.prototype.initHeader = function (oSortTypes) {\r\n if (!this.tHead) return;\r\n var cells = this.tHead.rows[0].cells;\r\n var doc = this.tHead.ownerDocument || this.tHead.document;\r\n this.sortTypes = oSortTypes || [];\r\n var l = cells.length;\r\n var img, c;\r\n for (var i = 0; i < l; i++) {\r\n c = cells[i];\r\n if (this.sortTypes[i] != null && this.sortTypes[i] != "None") {\r\n img = doc.createElement("IMG");\r\n img.src = "images/blank.png";\r\n c.appendChild(img);\r\n if (this.sortTypes[i] != null)\r\n c._sortType = this.sortTypes[i];\r\n if (typeof c.addEventListener != "undefined")\r\n c.addEventListener("click", this._headerOnclick, false);\r\n else if (typeof c.attachEvent != "undefined")\r\n c.attachEvent("onclick", this._headerOnclick);\r\n else\r\n c.onclick = this._headerOnclick;\r\n }\r\n else\r\n {\r\n c.setAttribute( "_sortType", oSortTypes[i] );\r\n c._sortType = "None";\r\n }\r\n }\r\n this.updateHeaderArrows();\r\n};\r\n\r\n// remove arrows and events\r\nSortableTable.prototype.uninitHeader = function () {\r\n if (!this.tHead) return;\r\n var cells = this.tHead.rows[0].cells;\r\n var l = cells.length;\r\n var c;\r\n for (var i = 0; i < l; i++) {\r\n c = cells[i];\r\n if (c._sortType != null && c._sortType != "None") {\r\n c.removeChild(c.lastChild);\r\n if (typeof c.removeEventListener != "undefined")\r\n c.removeEventListener("click", this._headerOnclick, false);\r\n else if (typeof c.detachEvent != "undefined")\r\n c.detachEvent("onclick", this._headerOnclick);\r\n c._sortType = null;\r\n c.removeAttribute( "_sortType" );\r\n }\r\n }\r\n};\r\n\r\nSortableTable.prototype.updateHeaderArrows = function () {\r\n if (!this.tHead) return;\r\n var cells = this.tHead.rows[0].cells;\r\n var l = cells.length;\r\n var img;\r\n for (var i = 0; i < l; i++) {\r\n if (cells[i]._sortType != null && cells[i]._sortType != "None") {\r\n img = cells[i].lastChild;\r\n if (i == this.sortColumn)\r\n img.className = "sort-arrow " + (this.descending ? "descending" : "ascending");\r\n else\r\n img.className = "sort-arrow";\r\n }\r\n }\r\n};\r\n\r\nSortableTable.prototype.headerOnclick = function (e) {\r\n // find TD element\r\n var el = e.target || e.srcElement;\r\n while (el.tagName != "TD")\r\n el = el.parentNode;\r\n\r\n this.sort(SortableTable.msie ? SortableTable.getCellIndex(el) : el.cellIndex);\r\n};\r\n\r\n// IE returns wrong cellIndex when columns are hidden\r\nSortableTable.getCellIndex = function (oTd) {\r\n var cells = oTd.parentNode.childNodes\r\n var l = cells.length;\r\n var i;\r\n for (i = 0; cells[i] != oTd && i < l; i++)\r\n ;\r\n return i;\r\n};\r\n\r\nSortableTable.prototype.getSortType = function (nColumn) {\r\n return this.sortTypes[nColumn] || "String";\r\n};\r\n\r\n// only nColumn is required\r\n// if bDescending is left out the old value is taken into account\r\n// if sSortType is left out the sort type is found from the sortTypes array\r\n\r\nSortableTable.prototype.sort = function (nColumn, bDescending, sSortType) {\r\n if (!this.tBody) return;\r\n if (sSortType == null)\r\n sSortType = this.getSortType(nColumn);\r\n\r\n // exit if None\r\n if (sSortType == "None")\r\n return;\r\n\r\n if (bDescending == null) {\r\n if (this.sortColumn != nColumn)\r\n this.descending = this.defaultDescending;\r\n else\r\n this.descending = !this.descending;\r\n }\r\n else\r\n this.descending = bDescending;\r\n\r\n this.sortColumn = nColumn;\r\n\r\n if (typeof this.onbeforesort == "function")\r\n this.onbeforesort();\r\n\r\n var f = this.getSortFunction(sSortType, nColumn);\r\n var a = this.getCache(sSortType, nColumn);\r\n var tBody = this.tBody;\r\n\r\n a.sort(f);\r\n\r\n if (this.descending)\r\n a.reverse();\r\n\r\n if (SortableTable.removeBeforeSort) {\r\n // remove from doc\r\n var nextSibling = tBody.nextSibling;\r\n var p = tBody.parentNode;\r\n p.removeChild(tBody);\r\n }\r\n\r\n // insert in the new order\r\n var l = a.length;\r\n for (var i = 0; i < l; i++)\r\n tBody.appendChild(a[i].element);\r\n\r\n if (SortableTable.removeBeforeSort) {\r\n // insert into doc\r\n p.insertBefore(tBody, nextSibling);\r\n }\r\n\r\n this.updateHeaderArrows();\r\n\r\n this.destroyCache(a);\r\n\r\n if (typeof this.onsort == "function")\r\n this.onsort();\r\n};\r\n\r\nSortableTable.prototype.asyncSort = function (nColumn, bDescending, sSortType) {\r\n var oThis = this;\r\n this._asyncsort = function () {\r\n oThis.sort(nColumn, bDescending, sSortType);\r\n };\r\n window.setTimeout(this._asyncsort, 1);\r\n};\r\n\r\nSortableTable.prototype.getCache = function (sType, nColumn) {\r\n if (!this.tBody) return [];\r\n var rows = this.tBody.rows;\r\n var l = rows.length;\r\n var a = new Array(l);\r\n var r;\r\n for (var i = 0; i < l; i++) {\r\n r = rows[i];\r\n a[i] = {\r\n value: this.getRowValue(r, sType, nColumn),\r\n element: r\r\n };\r\n };\r\n return a;\r\n};\r\n\r\nSortableTable.prototype.destroyCache = function (oArray) {\r\n var l = oArray.length;\r\n for (var i = 0; i < l; i++) {\r\n oArray[i].value = null;\r\n oArray[i].element = null;\r\n oArray[i] = null;\r\n }\r\n};\r\n\r\nSortableTable.prototype.getRowValue = function (oRow, sType, nColumn) {\r\n // if we have defined a custom getRowValue use that\r\n if (this._sortTypeInfo[sType] && this._sortTypeInfo[sType].getRowValue)\r\n return this._sortTypeInfo[sType].getRowValue(oRow, nColumn);\r\n\r\n var s;\r\n var c = oRow.cells[nColumn];\r\n if (typeof c.innerText != "undefined")\r\n s = c.innerText;\r\n else\r\n s = SortableTable.getInnerText(c);\r\n return this.getValueFromString(s, sType);\r\n};\r\n\r\nSortableTable.getInnerText = function (oNode) {\r\n var s = "";\r\n var cs = oNode.childNodes;\r\n var l = cs.length;\r\n for (var i = 0; i < l; i++) {\r\n switch (cs[i].nodeType) {\r\n case 1: //ELEMENT_NODE\r\n s += SortableTable.getInnerText(cs[i]);\r\n break;\r\n case 3: //TEXT_NODE\r\n s += cs[i].nodeValue;\r\n break;\r\n }\r\n }\r\n return s;\r\n};\r\n\r\nSortableTable.prototype.getValueFromString = function (sText, sType) {\r\n if (this._sortTypeInfo[sType])\r\n return this._sortTypeInfo[sType].getValueFromString( sText );\r\n return sText;\r\n /*\r\n switch (sType) {\r\n case "Number":\r\n return Number(sText);\r\n case "CaseInsensitiveString":\r\n return sText.toUpperCase();\r\n case "Date":\r\n var parts = sText.split("-");\r\n var d = new Date(0);\r\n d.setFullYear(parts[0]);\r\n d.setDate(parts[2]);\r\n d.setMonth(parts[1] - 1);\r\n return d.valueOf();\r\n }\r\n return sText;\r\n */\r\n };\r\n\r\nSortableTable.prototype.getSortFunction = function (sType, nColumn) {\r\n if (this._sortTypeInfo[sType])\r\n return this._sortTypeInfo[sType].compare;\r\n return SortableTable.basicCompare;\r\n};\r\n\r\nSortableTable.prototype.destroy = function () {\r\n this.uninitHeader();\r\n var win = this.document.parentWindow;\r\n if (win && typeof win.detachEvent != "undefined") { // only IE needs this\r\n win.detachEvent("onunload", this._onunload);\r\n }\r\n this._onunload = null;\r\n this.element = null;\r\n this.tHead = null;\r\n this.tBody = null;\r\n this.document = null;\r\n this._headerOnclick = null;\r\n this.sortTypes = null;\r\n this._asyncsort = null;\r\n this.onsort = null;\r\n};\r\n\r\n// Adds a sort type to all instance of SortableTable\r\n// sType : String - the identifier of the sort type\r\n// fGetValueFromString : function ( s : string ) : T - A function that takes a\r\n// string and casts it to a desired format. If left out the string is just\r\n// returned\r\n// fCompareFunction : function ( n1 : T, n2 : T ) : Number - A normal JS sort\r\n// compare function. Takes two values and compares them. If left out less than,\r\n// <, compare is used\r\n// fGetRowValue : function( oRow : HTMLTRElement, nColumn : int ) : T - A function\r\n// that takes the row and the column index and returns the value used to compare.\r\n// If left out then the innerText is first taken for the cell and then the\r\n// fGetValueFromString is used to convert that string the desired value and type\r\n\r\nSortableTable.prototype.addSortType = function (sType, fGetValueFromString, fCompareFunction, fGetRowValue) {\r\n this._sortTypeInfo[sType] = {\r\n type: sType,\r\n getValueFromString: fGetValueFromString || SortableTable.idFunction,\r\n compare: fCompareFunction || SortableTable.basicCompare,\r\n getRowValue: fGetRowValue\r\n };\r\n};\r\n\r\n// this removes the sort type from all instances of SortableTable\r\nSortableTable.prototype.removeSortType = function (sType) {\r\n delete this._sortTypeInfo[sType];\r\n};\r\n\r\nSortableTable.basicCompare = function compare(n1, n2) {\r\n if (n1.value < n2.value)\r\n return -1;\r\n if (n2.value < n1.value)\r\n return 1;\r\n return 0;\r\n};\r\n\r\nSortableTable.idFunction = function (x) {\r\n return x;\r\n};\r\n\r\nSortableTable.toUpperCase = function (s) {\r\n return s.toUpperCase();\r\n};\r\n\r\nSortableTable.toDate = function (s) {\r\n var parts = s.split("-");\r\n var d = new Date(0);\r\n d.setFullYear(parts[0]);\r\n d.setDate(parts[2]);\r\n d.setMonth(parts[1] - 1);\r\n return d.valueOf();\r\n};\r\n\r\n\r\n// add sort types\r\nSortableTable.prototype.addSortType("Number", Number);\r\nSortableTable.prototype.addSortType("CaseInsensitiveString", SortableTable.toUpperCase);\r\nSortableTable.prototype.addSortType("Date", SortableTable.toDate);\r\nSortableTable.prototype.addSortType("String");\r\n// None is a special case\r\n'}});