diff --git a/src/index.html b/src/index.html index d44fe4a8..31769f78 100644 --- a/src/index.html +++ b/src/index.html @@ -1,7 +1,7 @@ - + HTML Table Filter Generator @@ -68,8 +68,9 @@ diff --git a/src/tablefilter_all.js b/src/tablefilter_all.js index 47f5bcbb..d370a6aa 100644 --- a/src/tablefilter_all.js +++ b/src/tablefilter_all.js @@ -2731,71 +2731,90 @@ TF.prototype = { slcR.onchange = this.Evt._OnSlcResultsChange; }, - RemoveResultsPerPage: function() /*==================================================== - Removes results per page select + label =====================================================*/ - { - if(!this.hasGrid) return; - if( this.resultsPerPageSlc==null || this.resultsPerPage==null ) return; - var slcR, slcRSpan; - slcR = this.resultsPerPageSlc; - slcRSpan = tf_Id( this.prfxSlcResultsTxt+this.id ); - if( slcR!=null ) + RemoveResultsPerPage: function(){ + if(!this.hasGrid || !this.resultsPerPageSlc || !this.resultsPerPage){ + return; + } + var slcR = this.resultsPerPageSlc, + slcRSpan = tf_Id(this.prfxSlcResultsTxt+this.id); + if(slcR){ slcR.parentNode.removeChild( slcR ); - if( slcRSpan!=null ) + } + if(slcRSpan){ slcRSpan.parentNode.removeChild( slcRSpan ); + } this.resultsPerPageSlc = null; }, - SetHelpInstructions: function() /*==================================================== - Generates help instructions =====================================================*/ - { - if( this.helpInstrBtnEl!=null ) return; + SetHelpInstructions: function(){ + if(this.helpInstrBtnEl){ + return; + } var f = this.fObj; - this.helpInstrTgtId = f.help_instructions_target_id!=undefined //id of custom container element for instructions - ? f.help_instructions_target_id : null; - this.helpInstrContTgtId = f.help_instructions_container_target_id!=undefined //id of custom container element for instructions - ? f.help_instructions_container_target_id : null; - this.helpInstrText = f.help_instructions_text //defines help text - ? f.help_instructions_text : 'Use the filters above each column to filter and limit table data. ' + - 'Avanced searches can be performed by using the following operators:
' + - '<, <=, >, >=, =, *, !, {, }, ||, ' + - '&&, [empty], [nonempty], rgx:
These operators are described here:
' + - 'http://tablefilter.free.fr/#operators
'; - this.helpInstrHtml = f.help_instructions_html!=undefined - ? f.help_instructions_html : null; //defines help innerHtml - this.helpInstrBtnText = f.help_instructions_btn_text!=undefined - ? f.help_instructions_btn_text : '?'; //defines reset button text - this.helpInstrBtnHtml = f.help_instructions_btn_html!=undefined - ? f.help_instructions_btn_html : null; //defines reset button innerHtml - this.helpInstrBtnCssClass = f.help_instructions_btn_css_class!=undefined //defines css class for help button - ? f.help_instructions_btn_css_class : 'helpBtn'; - this.helpInstrContCssClass = f.help_instructions_container_css_class!=undefined //defines css class for help container - ? f.help_instructions_container_css_class : 'helpCont'; - this.helpInstrBtnEl = null; //help button element - this.helpInstrContEl = null; //help content div - this.helpInstrDefaultHtml = '

HTML Table Filter Generator v. '+ this.version +'

' + - 'http://tablefilter.free.fr
' + - '©2009-'+ this.year +' Max Guglielmi.
' + - 'Close
'; + //id of custom container element for instructions + this.helpInstrTgtId = f.help_instructions_target_id || null; + //id of custom container element for instructions + this.helpInstrContTgtId = f.help_instructions_container_target_id || + null; + //defines help text + this.helpInstrText = f.help_instructions_text ? + f.help_instructions_text : + 'Use the filters above each column to filter and limit table ' + + 'data. Avanced searches can be performed by using the following ' + + 'operators:
<, <=, >, ' + + '>=, =, *, !, {, }, ' + + '||,&&, [empty], [nonempty], ' + + 'rgx:
These operators are described here:
' + + 'http://tablefilter.free.fr/#operators
'; + //defines help innerHtml + this.helpInstrHtml = f.help_instructions_html || null; + //defines reset button text + this.helpInstrBtnText = f.help_instructions_btn_text || '?'; + //defines reset button innerHtml + this.helpInstrBtnHtml = f.help_instructions_btn_html || null; + //defines css class for help button + this.helpInstrBtnCssClass = f.help_instructions_btn_css_class || + 'helpBtn'; + //defines css class for help container + this.helpInstrContCssClass = f.help_instructions_container_css_class || + 'helpCont'; + //help button element + this.helpInstrBtnEl = null; + //help content div + this.helpInstrContEl = null; + this.helpInstrDefaultHtml = '

HTML Table ' + + 'Filter Generator v. '+ this.version +'

' + + '' + + 'http://tablefilter.free.fr
' + + '©2009-'+ this.year +' Max Guglielmi.' + + '
' + + 'Close
'; var helpspan = tf_CreateElm('span',['id',this.prfxHelpSpan+this.id]); var helpdiv = tf_CreateElm('div',['id',this.prfxHelpDiv+this.id]); //help button is added to defined element - if(this.helpInstrTgtId==null) this.SetTopDiv(); - var targetEl = ( this.helpInstrTgtId==null ) ? this.rDiv : tf_Id( this.helpInstrTgtId ); + if(!this.helpInstrTgtId){ + this.SetTopDiv(); + } + var targetEl = !this.helpInstrTgtId ? + this.rDiv : tf_Id(this.helpInstrTgtId); targetEl.appendChild(helpspan); - var divContainer = ( this.helpInstrContTgtId==null ) ? helpspan : tf_Id( this.helpInstrContTgtId ); + var divContainer = !this.helpInstrContTgtId ? + helpspan : tf_Id( this.helpInstrContTgtId ); - if(this.helpInstrBtnHtml == null) - { + if(!this.helpInstrBtnHtml){ divContainer.appendChild(helpdiv); - var helplink = tf_CreateElm( 'a', ['href','javascript:void(0);'] ); + var helplink = tf_CreateElm( 'a', ['href','javascript:void(0);']); helplink.className = this.helpInstrBtnCssClass; helplink.appendChild(tf_CreateText(this.helpInstrBtnText)); helpspan.appendChild(helplink); @@ -2807,9 +2826,7 @@ TF.prototype = { divContainer.appendChild(helpdiv); } - if(this.helpInstrHtml == null) - { - //helpdiv.appendChild(tf_CreateText(this.helpInstrText)); + if(!this.helpInstrHtml){ helpdiv.innerHTML = this.helpInstrText; helpdiv.className = this.helpInstrContCssClass; helpdiv.ondblclick = this.Evt._OnHelpBtnClick; @@ -2826,139 +2843,154 @@ TF.prototype = { this.helpInstrBtnEl = helpspan; }, - RemoveHelpInstructions: function() /*==================================================== - Removes help instructions =====================================================*/ - { - if(this.helpInstrBtnEl==null) return; + RemoveHelpInstructions: function() { + if(!this.helpInstrBtnEl){ + return; + } this.helpInstrBtnEl.parentNode.removeChild(this.helpInstrBtnEl); this.helpInstrBtnEl = null; - if(this.helpInstrContEl==null) return; + if(!this.helpInstrContEl){ + return; + } this.helpInstrContEl.parentNode.removeChild(this.helpInstrContEl); this.helpInstrContEl = null; }, - _ToggleHelp: function() /*==================================================== - Toggles help div =====================================================*/ - { - if(!this.helpInstrContEl) return; - var divDisplay = this.helpInstrContEl.style.display; - if(divDisplay == '' || divDisplay == 'none'){ - this.helpInstrContEl.style.display = 'block'; - var btnLeft = tf_ObjPosition(this.helpInstrBtnEl, [this.helpInstrBtnEl.nodeName])[0]; - if(!this.helpInstrContTgtId) - this.helpInstrContEl.style.left = (btnLeft - this.helpInstrContEl.clientWidth + 25) + 'px'; + _ToggleHelp: function(){ + if(!this.helpInstrContEl){ + return; + } + var divDisplay = this.helpInstrContEl.style.display; + if(divDisplay==='' || divDisplay==='none'){ + this.helpInstrContEl.style.display = 'block'; + var btnLeft = tf_ObjPosition( + this.helpInstrBtnEl, [this.helpInstrBtnEl.nodeName])[0]; + if(!this.helpInstrContTgtId){ + this.helpInstrContEl.style.left = + (btnLeft - this.helpInstrContEl.clientWidth + 25) + 'px'; + } + } else { + this.helpInstrContEl.style.display = 'none'; } - else this.helpInstrContEl.style.display = 'none'; }, - ChangePage: function( index ) - { + ChangePage: function(index){ this.EvtManager(this.Evt.name.changepage,{ pgIndex:index }); }, - _ChangePage: function( index ) /*==================================================== - Changes page - Param: - index: option index of paging select (numeric value) =====================================================*/ - { - if( !this.paging ) return; - if( index==undefined ) - index = (this.pageSelectorType==this.fltTypeSlc) ? + _ChangePage: function(index){ + if(!this.paging){ + return; + } + if(!index){ + index = this.pageSelectorType===this.fltTypeSlc ? this.pagingSlc.options.selectedIndex : (this.pagingSlc.value-1); - if( index>=0 && index<=(this.nbPages-1) ) - { - if(this.onBeforeChangePage) this.onBeforeChangePage.call(null, this, index); + } + if( index>=0 && index<=(this.nbPages-1) ){ + if(this.onBeforeChangePage){ + this.onBeforeChangePage.call(null, this, index); + } this.currentPageNb = parseInt(index)+1; - if(this.pageSelectorType==this.fltTypeSlc) + if(this.pageSelectorType===this.fltTypeSlc){ this.pagingSlc.options[index].selected = true; - else + } else { this.pagingSlc.value = this.currentPageNb; + } - if( this.rememberPageNb ) this.RememberPageNb( this.pgNbCookie ); - this.startPagingRow = (this.pageSelectorType==this.fltTypeSlc) - ? this.pagingSlc.value : (index*this.pagingLength); + if(this.rememberPageNb){ + this.RememberPageNb(this.pgNbCookie); + } + this.startPagingRow = (this.pageSelectorType===this.fltTypeSlc) ? + this.pagingSlc.value : (index*this.pagingLength); this.GroupByPage(); - if(this.onAfterChangePage) this.onAfterChangePage.call(null, this, index); + if(this.onAfterChangePage){ + this.onAfterChangePage.call(null, this, index); + } } }, - ChangeResultsPerPage: function() - { + ChangeResultsPerPage: function(){ this.EvtManager(this.Evt.name.changeresultsperpage); }, - _ChangeResultsPerPage: function() /*==================================================== - calculates rows to be displayed in a page - method called by nb results per page select =====================================================*/ - { - if( !this.paging ) return; + _ChangeResultsPerPage: function(){ + if(!this.paging){ + return; + } var slcR = this.resultsPerPageSlc; - var slcPagesSelIndex = (this.pageSelectorType==this.fltTypeSlc) - ? this.pagingSlc.selectedIndex : parseInt(this.pagingSlc.value-1); - this.pagingLength = parseInt(slcR.options[slcR.selectedIndex].value); + var slcPagesSelIndex = (this.pageSelectorType==this.fltTypeSlc) ? + this.pagingSlc.selectedIndex : + parseInt(this.pagingSlc.value-1,10); + this.pagingLength = parseInt(slcR.options[slcR.selectedIndex].value,10); this.startPagingRow = this.pagingLength*slcPagesSelIndex; - if( !isNaN(this.pagingLength) ) - { - if( this.startPagingRow>=this.nbFilterableRows ) + if(!isNaN(this.pagingLength)){ + if(this.startPagingRow>=this.nbFilterableRows){ this.startPagingRow = (this.nbFilterableRows-this.pagingLength); + } this.SetPagingInfo(); - if(this.pageSelectorType==this.fltTypeSlc) - { - var slcIndex = (this.pagingSlc.options.length-1<=slcPagesSelIndex ) - ? (this.pagingSlc.options.length-1) : slcPagesSelIndex; + if(this.pageSelectorType===this.fltTypeSlc){ + var slcIndex = + (this.pagingSlc.options.length-1<=slcPagesSelIndex ) ? + (this.pagingSlc.options.length-1) : slcPagesSelIndex; this.pagingSlc.options[slcIndex].selected = true; } - if( this.rememberPageLen ) this.RememberPageLength( this.pgLenCookie ); - }//if isNaN + if(this.rememberPageLen){ + this.RememberPageLength( this.pgLenCookie ); + } + } }, - ResetPage: function( name ) - { + ResetPage: function(name){ this.EvtManager(this.Evt.name.resetpage); }, - _ResetPage: function( name ) /*============================================== - re-sets page nb at page re-load - Params: - name: cookie name (string) ===============================================*/ - { - var pgnb = tf_ReadCookie(name); //reads the cookie - if( pgnb!='' ) + _ResetPage: function(name){ + var pgnb = tf_ReadCookie(name); + if(pgnb!==''){ this.ChangePage((pgnb-1)); + } }, - ResetPageLength: function( name ) - { + ResetPageLength: function(name){ this.EvtManager(this.Evt.name.resetpagelength); }, - _ResetPageLength: function( name ) /*============================================== - re-sets page length at page re-load - Params: - name: cookie name (string) ===============================================*/ - { - if(!this.paging) return; - var pglenIndex = tf_ReadCookie(name); //reads the cookie + _ResetPageLength: function(name){ + if(!this.paging){ + return; + } + var pglenIndex = tf_ReadCookie(name); - if( pglenIndex!='' ) - { + if(pglenIndex!==''){ this.resultsPerPageSlc.options[pglenIndex].selected = true; this.ChangeResultsPerPage(); } }, - AddPaging: function(filterTable) /*==================================================== - Adds paging feature if filter grid bar is already set @@ -2966,40 +2998,50 @@ TF.prototype = { - execFilter: if true table is filtered (boolean) =====================================================*/ - { - if( !this.hasGrid || this.paging ) return; + AddPaging: function(filterTable){ + if(!this.hasGrid || this.paging){ + return; + } this.paging = true; this.isPagingRemoved = true; this.SetPaging(); this.ResetValues(); - if(filterTable) this.Filter(); + if(filterTable){ + this.Filter(); + } }, - PopulateSelect: function(colIndex,isExternal,extSlcId) - { + PopulateSelect: function(colIndex,isExternal,extSlcId){ this.EvtManager( this.Evt.name.populateselect, { slcIndex:colIndex, slcExternal:isExternal, slcId:extSlcId } ); }, - _PopulateSelect: function(colIndex,isRefreshed,isExternal,extSlcId) /*==================================================== - populates drop-down filters =====================================================*/ - { - isExternal = (isExternal==undefined) ? false : isExternal; + _PopulateSelect: function(colIndex,isRefreshed,isExternal,extSlcId) { + isExternal = isExternal===undefined ? false : isExternal; var slcId = this.fltIds[colIndex]; - if( tf_Id(slcId)==null && !isExternal ) return; - if( tf_Id(extSlcId)==null && isExternal ) return; - var slc = (!isExternal) ? tf_Id(slcId) : tf_Id(extSlcId); - var o = this, row = this.tbl.rows; - var fillMethod = this.slcFillingMethod.tf_LCase(); - var optArray = [], slcInnerHtml = '', opt0; - var isCustomSlc = (this.hasCustomSlcOptions //custom select test - && this.customSlcOptions.cols.tf_Has(colIndex)); - var optTxt = []; //custom selects text - var activeFlt; + if((!tf_Id(slcId) && !isExternal) || + (!tf_Id(extSlcId) && isExternal)){ + return; + } + var slc = !isExternal ? tf_Id(slcId) : tf_Id(extSlcId), + o = this, + row = this.tbl.rows, + matchCase = this.matchCase, + fillMethod = this.slcFillingMethod.tf_LCase(), + optArray = [], + slcInnerHtml = '', + opt0, + //custom select test + isCustomSlc = (this.hasCustomSlcOptions && + this.customSlcOptions.cols.tf_Has(colIndex)); + //custom selects text + var optTxt = [], + activeFlt; if(isRefreshed && this.activeFilterId){ activeFlt = this.activeFilterId.split('_')[0]; activeFlt = activeFlt.split(this.prfxFlt)[1]; @@ -3007,46 +3049,70 @@ TF.prototype = { /*** remember grid values ***/ var flts_values = [], fltArr = []; - if(this.rememberGridValues) - { - flts_values = tf_CookieValueArray(this.fltsValuesCookie, this.separator); - if(flts_values != undefined && flts_values.toString().tf_Trim() != ''){ - if(this.hasCustomSlcOptions && this.customSlcOptions.cols.tf_Has(colIndex)){ + if(this.rememberGridValues){ + flts_values = tf_CookieValueArray( + this.fltsValuesCookie, this.separator); + if(flts_values && flts_values.toString().tf_Trim()!==''){ + if(isCustomSlc){ fltArr.push(flts_values[colIndex]); - } else { fltArr = flts_values[colIndex].split(' '+o.orOperator+' '); } + } else { + fltArr = flts_values[colIndex].split(' '+o.orOperator+' '); + } } } - var excludedOpts = null, filteredDataCol = null; - if(isRefreshed && this.disableExcludedOptions){ excludedOpts = []; filteredDataCol = []; } + var excludedOpts = null, + filteredDataCol = null; + if(isRefreshed && this.disableExcludedOptions){ + excludedOpts = []; + filteredDataCol = []; + } - for(var k=this.refRow; k'; + // adds 1st option + function AddOpt0(){ + if(fillMethod === 'innerhtml'){ + slcInnerHtml +=''; + } else { - var opt0 = tf_CreateOpt((!o.enableSlcResetFilter ? '' : o.displayAllText),''); - if(!o.enableSlcResetFilter) opt0.style.display = 'none'; + var opt0 = tf_CreateOpt( + (!o.enableSlcResetFilter ? '' : o.displayAllText),''); + if(!o.enableSlcResetFilter){ + opt0.style.display = 'none'; + } slc.appendChild(opt0); if(o.enableEmptyOption){ var opt1 = tf_CreateOpt(o.emptyText,o.emOperator); @@ -3112,58 +3200,73 @@ TF.prototype = { } } - function AddOpts() - {// populates select + // populates select + function AddOpts(){ var slcValue = slc.value; slc.innerHTML = ''; AddOpt0(); - for(var y=0; y'+lbl+''; + } + slcInnerHtml += ''; } else { var opt; //fill select on demand - if(o.fillSlcOnDemand && slcValue==optArray[y] && o['col'+colIndex]==o.fltTypeSlc) - opt = tf_CreateOpt( lbl, val, true ); - else{ - if( o['col'+colIndex]!=o.fltTypeMulti ) - opt = tf_CreateOpt( lbl, val, - (flts_values[colIndex]!=' ' && val==flts_values[colIndex]) - ? true : false ); - else - { - opt = tf_CreateOpt( lbl, val, - (fltArr.tf_Has(optArray[y].tf_MatchCase(o.matchCase),o.matchCase) - || fltArr.toString().indexOf(val)!= -1) - ? true : false ); + if(o.fillSlcOnDemand && slcValue==optArray[y] && + o['col'+colIndex]===o.fltTypeSlc){ + opt = tf_CreateOpt(lbl, val, true); + } else { + if(o['col'+colIndex]!=o.fltTypeMulti){ + opt = tf_CreateOpt( + lbl, + val, + (flts_values[colIndex]!==' ' && + val==flts_values[colIndex]) ? true : false + ); + } else { + opt = tf_CreateOpt( + lbl, + val, + (fltArr.tf_Has( + optArray[y].tf_MatchCase( + o.matchCase),o.matchCase) || + fltArr.toString().indexOf(val)!== -1) ? + true : false + ); } } - if(isDisabled) opt.disabled = true; + if(isDisabled){ + opt.disabled = true; + } slc.appendChild(opt); } }// for y - if( fillMethod == 'innerhtml' ) slc.innerHTML += slcInnerHtml; + if(fillMethod === 'innerhtml'){ + slc.innerHTML += slcInnerHtml; + } slc.setAttribute('filled','1'); }// fn AddOpt }, - __deferMultipleSelection: function(slc,index,filter) /*==================================================== - IE bug: it seems there is no way to make multiple selections programatically, only last @@ -3172,29 +3275,27 @@ TF.prototype = { - Work-around: defer selection with a setTimeout If you find a more elegant solution to this let me know ;-) - - For the moment only this solution seems - to work! + - For the moment only this solution seems to work! - Params: - slc = select object (select obj) - index to be selected (integer) - execute filtering (boolean) =====================================================*/ - { - if(slc.nodeName.tf_LCase() != 'select') return; - var doFilter = (filter==undefined) ? false : filter; + __deferMultipleSelection: function(slc,index,filter){ + if(slc.nodeName.tf_LCase() !== 'select'){ + return; + } + var doFilter = filter===undefined ? false : filter; var o = this; - window.setTimeout( - function(){ - slc.options[0].selected = false; + window.setTimeout(function(){ + slc.options[0].selected = false; - if(slc.options[index].value=='') - slc.options[index].selected = false; - else - slc.options[index].selected = true; - if(doFilter) o.Filter(); - }, - .1 - ); + if(slc.options[index].value=='') + slc.options[index].selected = false; + else + slc.options[index].selected = true; + if(doFilter) o.Filter(); + }, 0.1); }, __getCustomValues: function(colIndex)