mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-05-10 02:16:40 +02:00
Code formatting
This commit is contained in:
parent
1e50d1bc0f
commit
40ec690dbc
|
@ -1,8 +1,8 @@
|
||||||
------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
- HTML Table Filter Generator v2.5
|
- HTML Table Filter Generator v2.5
|
||||||
- By Max Guglielmi (tablefilter.free.fr)
|
- By Max Guglielmi (tablefilter.free.fr)
|
||||||
- Licensed under the MIT License
|
- Licensed under the MIT License
|
||||||
--------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
Copyright (c) 2009-2014 Max Guglielmi
|
Copyright (c) 2009-2014 Max Guglielmi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
@ -23,13 +23,13 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
--------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
- Special credit to:
|
- Special credit to:
|
||||||
Cedric Wartel, cnx.claude@free.fr, Florent Hirchy, Váry Péter,
|
Cedric Wartel, cnx.claude@free.fr, Florent Hirchy, Váry Péter,
|
||||||
Anthony Maes, Nuovella Williams, Fuggerbit, Venkata Seshagiri Rao
|
Anthony Maes, Nuovella Williams, Fuggerbit, Venkata Seshagiri Rao
|
||||||
Raya, Piepiax, Manuel Kern, Baladhandayutham for active contribution
|
Raya, Piepiax, Manuel Kern, Baladhandayutham for active contribution
|
||||||
and/or inspiration
|
and/or inspiration
|
||||||
------------------------------------------------------------------------*/
|
------------------------------------------------------------------------ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TF object constructor
|
* TF object constructor
|
||||||
|
@ -2334,9 +2334,11 @@ TF.prototype = {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var slcPages;
|
||||||
|
|
||||||
// Paging drop-down list selector
|
// Paging drop-down list selector
|
||||||
if(this.pageSelectorType === this.fltTypeSlc){
|
if(this.pageSelectorType === this.fltTypeSlc){
|
||||||
var slcPages = tf_CreateElm(
|
slcPages = tf_CreateElm(
|
||||||
this.fltTypeSlc, ['id',this.prfxSlcPages+this.id]);
|
this.fltTypeSlc, ['id',this.prfxSlcPages+this.id]);
|
||||||
slcPages.className = this.pgSlcCssClass;
|
slcPages.className = this.pgSlcCssClass;
|
||||||
slcPages.onchange = this.Evt._OnSlcPagesChange;
|
slcPages.onchange = this.Evt._OnSlcPagesChange;
|
||||||
|
@ -2344,7 +2346,7 @@ TF.prototype = {
|
||||||
|
|
||||||
// Paging input selector
|
// Paging input selector
|
||||||
if(this.pageSelectorType === this.fltTypeInp){
|
if(this.pageSelectorType === this.fltTypeInp){
|
||||||
var slcPages = tf_CreateElm(
|
slcPages = tf_CreateElm(
|
||||||
this.fltTypeInp,
|
this.fltTypeInp,
|
||||||
['id',this.prfxSlcPages+this.id],
|
['id',this.prfxSlcPages+this.id],
|
||||||
['value',this.currentPageNb]
|
['value',this.currentPageNb]
|
||||||
|
@ -2481,196 +2483,239 @@ TF.prototype = {
|
||||||
this.isPagingRemoved = false;
|
this.isPagingRemoved = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
RemovePaging: function()
|
|
||||||
/*====================================================
|
/*====================================================
|
||||||
- Removes paging elements
|
- Removes paging elements
|
||||||
=====================================================*/
|
=====================================================*/
|
||||||
{
|
RemovePaging: function(){
|
||||||
if(!this.hasGrid) return;
|
if(!this.hasGrid || !this.pagingSlc){
|
||||||
if( this.pagingSlc==null ) return;
|
return;
|
||||||
var btnNextSpan, btnPrevSpan, btnLastSpan, btnFirstSpan;// btns containers
|
}
|
||||||
|
|
||||||
|
// btns containers
|
||||||
|
var btnNextSpan, btnPrevSpan, btnLastSpan, btnFirstSpan;
|
||||||
var pgBeforeSpan, pgAfterSpan, pgspan;
|
var pgBeforeSpan, pgAfterSpan, pgspan;
|
||||||
btnNextSpan = tf_Id(this.prfxBtnNextSpan+this.id);
|
btnNextSpan = tf_Id(this.prfxBtnNextSpan+this.id);
|
||||||
btnPrevSpan = tf_Id(this.prfxBtnPrevSpan+this.id);
|
btnPrevSpan = tf_Id(this.prfxBtnPrevSpan+this.id);
|
||||||
btnLastSpan = tf_Id(this.prfxBtnLastSpan+this.id);
|
btnLastSpan = tf_Id(this.prfxBtnLastSpan+this.id);
|
||||||
btnFirstSpan = tf_Id(this.prfxBtnFirstSpan+this.id);
|
btnFirstSpan = tf_Id(this.prfxBtnFirstSpan+this.id);
|
||||||
pgBeforeSpan = tf_Id(this.prfxPgBeforeSpan+this.id);//span containing 'Page' text
|
//span containing 'Page' text
|
||||||
pgAfterSpan = tf_Id(this.prfxPgAfterSpan+this.id);//span containing 'of' text
|
pgBeforeSpan = tf_Id(this.prfxPgBeforeSpan+this.id);
|
||||||
pgspan = tf_Id(this.prfxPgSpan+this.id);//span containing nb of pages
|
//span containing 'of' text
|
||||||
|
pgAfterSpan = tf_Id(this.prfxPgAfterSpan+this.id);
|
||||||
|
//span containing nb of pages
|
||||||
|
pgspan = tf_Id(this.prfxPgSpan+this.id);
|
||||||
|
|
||||||
this.pagingSlc.parentNode.removeChild(this.pagingSlc);
|
this.pagingSlc.parentNode.removeChild(this.pagingSlc);
|
||||||
|
|
||||||
if( btnNextSpan!=null )
|
if(btnNextSpan){
|
||||||
btnNextSpan.parentNode.removeChild( btnNextSpan );
|
btnNextSpan.parentNode.removeChild( btnNextSpan );
|
||||||
|
}
|
||||||
|
|
||||||
if( btnPrevSpan!=null )
|
if(btnPrevSpan){
|
||||||
btnPrevSpan.parentNode.removeChild( btnPrevSpan );
|
btnPrevSpan.parentNode.removeChild( btnPrevSpan );
|
||||||
|
}
|
||||||
|
|
||||||
if( btnLastSpan!=null )
|
if(btnLastSpan){
|
||||||
btnLastSpan.parentNode.removeChild( btnLastSpan );
|
btnLastSpan.parentNode.removeChild( btnLastSpan );
|
||||||
|
}
|
||||||
|
|
||||||
if( btnFirstSpan!=null )
|
if(btnFirstSpan){
|
||||||
btnFirstSpan.parentNode.removeChild( btnFirstSpan );
|
btnFirstSpan.parentNode.removeChild( btnFirstSpan );
|
||||||
|
}
|
||||||
|
|
||||||
if( pgBeforeSpan!=null )
|
if(pgBeforeSpan){
|
||||||
pgBeforeSpan.parentNode.removeChild( pgBeforeSpan );
|
pgBeforeSpan.parentNode.removeChild( pgBeforeSpan );
|
||||||
|
}
|
||||||
|
|
||||||
if( pgAfterSpan!=null )
|
if(pgAfterSpan){
|
||||||
pgAfterSpan.parentNode.removeChild( pgAfterSpan );
|
pgAfterSpan.parentNode.removeChild( pgAfterSpan );
|
||||||
|
}
|
||||||
|
|
||||||
if( pgspan!=null )
|
if(pgspan){
|
||||||
pgspan.parentNode.removeChild( pgspan );
|
pgspan.parentNode.removeChild( pgspan );
|
||||||
|
}
|
||||||
|
|
||||||
this.pagingBtnEvents = null;
|
this.pagingBtnEvents = null;
|
||||||
this.pagingSlc = null;
|
this.pagingSlc = null;
|
||||||
this.isPagingRemoved = true;
|
this.isPagingRemoved = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
SetPagingInfo: function( validRows )
|
|
||||||
/*====================================================
|
/*====================================================
|
||||||
- calculates page # according to valid rows
|
- calculates page # according to valid rows
|
||||||
- refreshes paging select according to page #
|
- refreshes paging select according to page #
|
||||||
- Calls GroupByPage method
|
- Calls GroupByPage method
|
||||||
=====================================================*/
|
=====================================================*/
|
||||||
{
|
SetPagingInfo: function(validRows){
|
||||||
var row = this.tbl.rows;
|
var rows = this.tbl.rows;
|
||||||
var mdiv = ( this.pagingTgtId==null ) ? this.mDiv : tf_Id( this.pagingTgtId );
|
var mdiv = !this.pagingTgtId ? this.mDiv : tf_Id(this.pagingTgtId);
|
||||||
var pgspan = tf_Id(this.prfxPgSpan+this.id);
|
var pgspan = tf_Id(this.prfxPgSpan+this.id);
|
||||||
|
//stores valid rows indexes
|
||||||
|
if(validRows && validRows.length>0){
|
||||||
|
this.validRowsIndex = validRows;
|
||||||
|
} else {
|
||||||
|
//re-sets valid rows indexes array
|
||||||
|
this.validRowsIndex = [];
|
||||||
|
|
||||||
if( validRows!=undefined ) this.validRowsIndex = validRows;//stores valid rows index
|
//counts rows to be grouped
|
||||||
else
|
for(var j=this.refRow; j<this.nbRows; j++){
|
||||||
{
|
var row = rows[j];
|
||||||
this.validRowsIndex = [];//re-sets valid rows index
|
if(!row){
|
||||||
|
continue;
|
||||||
for(var j=this.refRow; j<this.nbRows; j++)//counts rows to be grouped
|
}
|
||||||
{
|
var isRowValid = row.getAttribute('validRow');
|
||||||
if(!row[j]) continue;
|
if(isRowValid==='true' || !isRowValid){
|
||||||
var isRowValid = row[j].getAttribute('validRow');
|
this.validRowsIndex.push(j);
|
||||||
if(isRowValid=='true' || isRowValid==null)
|
}
|
||||||
this.validRowsIndex.push(j);
|
}
|
||||||
}//for j
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.nbPages = Math.ceil( this.validRowsIndex.length/this.pagingLength );//calculates nb of pages
|
//calculate nb of pages
|
||||||
pgspan.innerHTML = this.nbPages; //refresh page nb span
|
this.nbPages = Math.ceil(this.validRowsIndex.length/this.pagingLength);
|
||||||
if(this.pageSelectorType==this.fltTypeSlc)
|
//refresh page nb span
|
||||||
this.pagingSlc.innerHTML = '';//select clearing shortcut
|
pgspan.innerHTML = this.nbPages;
|
||||||
|
//select clearing shortcut
|
||||||
|
if(this.pageSelectorType===this.fltTypeSlc){
|
||||||
|
this.pagingSlc.innerHTML = '';
|
||||||
|
}
|
||||||
|
|
||||||
if( this.nbPages>0 )
|
if(this.nbPages>0){
|
||||||
{
|
|
||||||
mdiv.style.visibility = 'visible';
|
mdiv.style.visibility = 'visible';
|
||||||
if(this.pageSelectorType==this.fltTypeSlc)
|
if(this.pageSelectorType===this.fltTypeSlc){
|
||||||
for(var z=0; z<this.nbPages; z++)
|
for(var z=0; z<this.nbPages; z++){
|
||||||
{
|
var currOpt = new Option(
|
||||||
var currOpt = new Option((z+1),z*this.pagingLength,false,false);
|
(z+1),
|
||||||
|
z*this.pagingLength,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
this.pagingSlc.options[z] = currOpt;
|
this.pagingSlc.options[z] = currOpt;
|
||||||
}
|
}
|
||||||
else this.pagingSlc.value = this.currentPageNb; //input type
|
} else{
|
||||||
|
//input type
|
||||||
|
this.pagingSlc.value = this.currentPageNb;
|
||||||
|
}
|
||||||
|
|
||||||
} else {/*** if no results paging select and buttons are hidden ***/
|
} else {
|
||||||
|
/*** if no results paging select and buttons are hidden ***/
|
||||||
mdiv.style.visibility = 'hidden';
|
mdiv.style.visibility = 'hidden';
|
||||||
}
|
}
|
||||||
this.GroupByPage( this.validRowsIndex );
|
this.GroupByPage(this.validRowsIndex);
|
||||||
},
|
},
|
||||||
|
|
||||||
GroupByPage: function( validRows )
|
|
||||||
/*====================================================
|
/*====================================================
|
||||||
- Displays current page rows
|
- Displays current page rows
|
||||||
=====================================================*/
|
=====================================================*/
|
||||||
{
|
GroupByPage: function(validRows){
|
||||||
var row = this.tbl.rows;
|
var rows = this.tbl.rows;
|
||||||
var paging_end_row = parseInt( this.startPagingRow ) + parseInt( this.pagingLength );
|
var paging_end_row = parseInt(this.startPagingRow, 10) +
|
||||||
|
parseInt(this.pagingLength, 10);
|
||||||
|
|
||||||
if( validRows!=undefined ) this.validRowsIndex = validRows;//stores valid rows index
|
//store valid rows indexes
|
||||||
|
if(validRows){
|
||||||
|
this.validRowsIndex = validRows;
|
||||||
|
}
|
||||||
|
|
||||||
for(h=0; h<this.validRowsIndex.length; h++)
|
//this loop shows valid rows of current page
|
||||||
{//this loop shows valid rows of current page
|
for(var h=0; h<this.validRowsIndex.length; h++){
|
||||||
if( h>=this.startPagingRow && h<paging_end_row )
|
var r = rows[ this.validRowsIndex[h] ];
|
||||||
{
|
if(h>=this.startPagingRow && h<paging_end_row){
|
||||||
var r = row[ this.validRowsIndex[h] ];
|
if(r.getAttribute('validRow')==='true' ||
|
||||||
if(r.getAttribute('validRow')=='true' || r.getAttribute('validRow')==undefined)
|
!r.getAttribute('validRow')){
|
||||||
r.style.display = '';
|
r.style.display = '';
|
||||||
if(this.alternateBgs) this.SetRowBg(this.validRowsIndex[h],h);
|
}
|
||||||
|
if(this.alternateBgs){
|
||||||
|
this.SetRowBg(this.validRowsIndex[h], h);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
row[ this.validRowsIndex[h] ].style.display = 'none';
|
r.style.display = 'none';
|
||||||
if(this.alternateBgs) this.RemoveRowBg(this.validRowsIndex[h]);
|
if(this.alternateBgs){
|
||||||
|
this.RemoveRowBg(this.validRowsIndex[h]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.nbVisibleRows = this.validRowsIndex.length;
|
this.nbVisibleRows = this.validRowsIndex.length;
|
||||||
this.isStartBgAlternate = false;
|
this.isStartBgAlternate = false;
|
||||||
this.ApplyGridProps();//re-applies filter behaviours after filtering process
|
//re-applies filter behaviours after filtering process
|
||||||
|
this.ApplyGridProps();
|
||||||
},
|
},
|
||||||
|
|
||||||
SetPage: function( cmd )
|
|
||||||
/*====================================================
|
/*====================================================
|
||||||
- If paging set true shows page according to
|
- If paging set true shows page according to
|
||||||
param value (string or number):
|
param value (string or number):
|
||||||
- strings: 'next','previous','last','first' or
|
- strings: 'next','previous','last','first' or
|
||||||
- number: page number
|
- number: page number
|
||||||
=====================================================*/
|
=====================================================*/
|
||||||
{
|
SetPage: function(cmd){
|
||||||
if( this.hasGrid && this.paging )
|
if(!this.hasGrid || !this.paging){
|
||||||
{
|
return;
|
||||||
var btnEvt = this.pagingBtnEvents, cmdtype = typeof cmd;
|
}
|
||||||
if(cmdtype=='string')
|
var btnEvt = this.pagingBtnEvents,
|
||||||
{
|
cmdtype = typeof cmd;
|
||||||
switch(cmd.tf_LCase())
|
if(cmdtype==='string'){
|
||||||
{
|
switch(cmd.tf_LCase()){
|
||||||
case 'next':
|
case 'next':
|
||||||
btnEvt.next();
|
btnEvt.next();
|
||||||
break;
|
break;
|
||||||
case 'previous':
|
case 'previous':
|
||||||
btnEvt.prev();
|
btnEvt.prev();
|
||||||
break;
|
break;
|
||||||
case 'last':
|
case 'last':
|
||||||
btnEvt.last();
|
btnEvt.last();
|
||||||
break;
|
break;
|
||||||
case 'first':
|
case 'first':
|
||||||
btnEvt.first();
|
btnEvt.first();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
btnEvt.next();
|
btnEvt.next();
|
||||||
break;
|
break;
|
||||||
}//switch
|
|
||||||
}
|
}
|
||||||
if(cmdtype=='number') this.ChangePage( (cmd-1) );
|
}
|
||||||
}// this.hasGrid
|
if(cmdtype==='number'){
|
||||||
|
this.ChangePage(cmd-1);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
SetResultsPerPage: function()
|
|
||||||
/*====================================================
|
/*====================================================
|
||||||
- Generates results per page select + label
|
- Generates results per page select + label
|
||||||
=====================================================*/
|
=====================================================*/
|
||||||
{
|
SetResultsPerPage: function(){
|
||||||
if(!this.hasGrid && !this.isFirstLoad) return;
|
if(!this.hasGrid && !this.isFirstLoad){
|
||||||
if( this.resultsPerPageSlc!=null || this.resultsPerPage==null ) return;
|
return;
|
||||||
|
}
|
||||||
|
if(this.resultsPerPageSlc || !this.resultsPerPage){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Change nb results per page event
|
//Change nb results per page event
|
||||||
if(!this.Evt._OnSlcResultsChange)
|
if(!this.Evt._OnSlcResultsChange){
|
||||||
{
|
|
||||||
var o = this;
|
var o = this;
|
||||||
this.Evt._OnSlcResultsChange = function()
|
|
||||||
/*====================================================
|
/*====================================================
|
||||||
- onchange event for results per page select
|
- onchange event for results per page select
|
||||||
=====================================================*/
|
=====================================================*/
|
||||||
{
|
this.Evt._OnSlcResultsChange = function(){
|
||||||
o.ChangeResultsPerPage();
|
o.ChangeResultsPerPage();
|
||||||
this.blur();
|
this.blur();
|
||||||
//ie only: blur is not enough...
|
//ie only: blur is not enough...
|
||||||
if(this.parentNode && tf_isIE)
|
if(this.parentNode && tf_isIE){
|
||||||
this.parentNode.focus();
|
this.parentNode.focus();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var slcR = tf_CreateElm( this.fltTypeSlc,['id',this.prfxSlcResults+this.id] );
|
var slcR = tf_CreateElm(
|
||||||
|
this.fltTypeSlc, ['id',this.prfxSlcResults+this.id]);
|
||||||
slcR.className = this.resultsSlcCssClass;
|
slcR.className = this.resultsSlcCssClass;
|
||||||
var slcRText = this.resultsPerPage[0], slcROpts = this.resultsPerPage[1];
|
var slcRText = this.resultsPerPage[0],
|
||||||
var slcRSpan = tf_CreateElm( 'span',['id',this.prfxSlcResultsTxt+this.id] );
|
slcROpts = this.resultsPerPage[1];
|
||||||
|
var slcRSpan = tf_CreateElm(
|
||||||
|
'span',['id',this.prfxSlcResultsTxt+this.id]);
|
||||||
slcRSpan.className = this.resultsSpanCssClass;
|
slcRSpan.className = this.resultsSpanCssClass;
|
||||||
|
|
||||||
// results per page select is added to defined element
|
// results per page select is added to external element
|
||||||
if(this.resultsPerPageTgtId==null) this.SetTopDiv();
|
if(!this.resultsPerPageTgtId){
|
||||||
|
this.SetTopDiv();
|
||||||
|
}
|
||||||
var targetEl = ( this.resultsPerPageTgtId==null ) ? this.rDiv : tf_Id( this.resultsPerPageTgtId );
|
var targetEl = ( this.resultsPerPageTgtId==null ) ? this.rDiv : tf_Id( this.resultsPerPageTgtId );
|
||||||
slcRSpan.appendChild(tf_CreateText(slcRText));
|
slcRSpan.appendChild(tf_CreateText(slcRText));
|
||||||
targetEl.appendChild(slcRSpan);
|
targetEl.appendChild(slcRSpan);
|
||||||
|
@ -6504,4 +6549,4 @@ function tf_hasClass(elm,cl){ return tf_HasClass(elm,cl); }
|
||||||
function tf_isValidDate(dateStr,format){ return tf_IsValidDate(dateStr,format); }
|
function tf_isValidDate(dateStr,format){ return tf_IsValidDate(dateStr,format); }
|
||||||
function tf_formatDate(dateStr,format){ return tf_FormatDate(dateStr,format); }
|
function tf_formatDate(dateStr,format){ return tf_FormatDate(dateStr,format); }
|
||||||
function tf_removeNbFormat(data,format){ return tf_RemoveNbFormat(data,format); }
|
function tf_removeNbFormat(data,format){ return tf_RemoveNbFormat(data,format); }
|
||||||
/* ---
|
/* --- */
|
Loading…
Reference in a new issue