/*------------------------------------------------------------------------ - HTML Table Filter Generator - Populate Select filters feature v1.2 - By Max Guglielmi (tablefilter.free.fr) - Licensed under the MIT License -------------------------------------------------------------------------*/ TF.prototype.PopulateSelect = function(colIndex,isExternal,extSlcId) { this.EvtManager( this.Evt.name.populateselect, { slcIndex:colIndex, slcExternal:isExternal, slcId:extSlcId } ); } TF.prototype._PopulateSelect = function(colIndex,isRefreshed,isExternal,extSlcId) /*==================================================== - populates drop-down filters =====================================================*/ { 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(isRefreshed && this.activeFilterId){ activeFlt = this.activeFilterId.split('_')[0]; activeFlt = activeFlt.split(this.prfxFlt)[1]; } /*** 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)){ fltArr.push(flts_values[colIndex]); } else { fltArr = flts_values[colIndex].split(' '+o.orOperator+' '); } } } var excludedOpts = null, filteredDataCol = null; if(isRefreshed && this.disableExcludedOptions){ excludedOpts = []; filteredDataCol = []; } for(var k=this.refRow; k'; else { 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); slc.appendChild(opt1); } if(o.enableNonEmptyOption){ var opt2 = tf_CreateOpt(o.nonEmptyText,o.nmOperator); slc.appendChild(opt2); } } } function AddOpts() {// populates select var slcValue = slc.value; slc.innerHTML = ''; AddOpt0(); for(var y=0; y'+lbl+''; } 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(isDisabled) opt.disabled = true; slc.appendChild(opt); } }// for y if( fillMethod == 'innerhtml' ) slc.innerHTML += slcInnerHtml; slc.setAttribute('filled','1'); }// fn AddOpt } TF.prototype.__deferMultipleSelection = function(slc,index,filter) /*==================================================== - IE bug: it seems there is no way to make multiple selections programatically, only last selection is kept (multiple select previously populated via DOM) - 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! - 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; var o = this; 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 ); } TF.prototype.__getCustomValues = function(colIndex) /*==================================================== - Returns an array [[values],[texts]] with custom values for a given filter - Param: column index (integer) =====================================================*/ { if(colIndex==undefined) return; var isCustomSlc = (this.hasCustomSlcOptions //custom select test && this.customSlcOptions.cols.tf_Has(colIndex)); if(!isCustomSlc) return; var optTxt = [], optArray = []; var index = this.customSlcOptions.cols.tf_IndexByValue(colIndex); var slcValues = this.customSlcOptions.values[index]; var slcTexts = this.customSlcOptions.texts[index]; var slcSort = this.customSlcOptions.sorts[index]; for(var r=0; r