mirror of
https://github.com/koalyptus/TableFilter.git
synced 2026-03-17 16:10:04 +01:00
Started decommissioning legacy persistence implementation
This commit is contained in:
parent
7c97b70873
commit
1ee1e306fd
13 changed files with 178 additions and 750 deletions
|
|
@ -4,13 +4,13 @@ import Types from '../types';
|
|||
import Str from '../string';
|
||||
import Event from '../event';
|
||||
|
||||
export class Paging extends Feature{
|
||||
export class Paging extends Feature {
|
||||
|
||||
/**
|
||||
* Pagination component
|
||||
* @param {Object} tf TableFilter instance
|
||||
*/
|
||||
constructor(tf){
|
||||
constructor(tf) {
|
||||
super(tf, 'paging');
|
||||
|
||||
// Configuration object
|
||||
|
|
@ -57,23 +57,23 @@ export class Paging extends Feature{
|
|||
//defines next page button html
|
||||
this.btnNextPageHtml = f.btn_next_page_html ||
|
||||
(!tf.enableIcons ? null :
|
||||
'<input type="button" value="" class="'+this.btnPageCssClass +
|
||||
' nextPage" title="Next page" />');
|
||||
'<input type="button" value="" class="' + this.btnPageCssClass +
|
||||
' nextPage" title="Next page" />');
|
||||
//defines previous page button html
|
||||
this.btnPrevPageHtml = f.btn_prev_page_html ||
|
||||
(!tf.enableIcons ? null :
|
||||
'<input type="button" value="" class="'+this.btnPageCssClass +
|
||||
' previousPage" title="Previous page" />');
|
||||
'<input type="button" value="" class="' + this.btnPageCssClass +
|
||||
' previousPage" title="Previous page" />');
|
||||
//defines last page button html
|
||||
this.btnFirstPageHtml = f.btn_first_page_html ||
|
||||
(!tf.enableIcons ? null :
|
||||
'<input type="button" value="" class="'+this.btnPageCssClass +
|
||||
' firstPage" title="First page" />');
|
||||
'<input type="button" value="" class="' + this.btnPageCssClass +
|
||||
' firstPage" title="First page" />');
|
||||
//defines previous page button html
|
||||
this.btnLastPageHtml = f.btn_last_page_html ||
|
||||
(!tf.enableIcons ? null :
|
||||
'<input type="button" value="" class="'+this.btnPageCssClass +
|
||||
' lastPage" title="Last page" />');
|
||||
'<input type="button" value="" class="' + this.btnPageCssClass +
|
||||
' lastPage" title="Last page" />');
|
||||
//defines text preceeding page selector drop-down
|
||||
this.pageText = f.page_text || ' Page ';
|
||||
//defines text after page selector drop-down
|
||||
|
|
@ -81,7 +81,7 @@ export class Paging extends Feature{
|
|||
//css class for span containing tot nb of pages
|
||||
this.nbPgSpanCssClass = f.nb_pages_css_class || 'nbpg';
|
||||
//enables/disables paging buttons
|
||||
this.hasPagingBtns = f.paging_btns===false ? false : true;
|
||||
this.hasPagingBtns = f.paging_btns === false ? false : true;
|
||||
//defines previous page button html
|
||||
this.pageSelectorType = f.page_selector_type || tf.fltTypeSlc;
|
||||
//calls function before page is changed
|
||||
|
|
@ -123,45 +123,45 @@ export class Paging extends Feature{
|
|||
var start_row = tf.refRow;
|
||||
var nrows = tf.nbRows;
|
||||
//calculates page nb
|
||||
this.nbPages = Math.ceil((nrows-start_row)/this.pagingLength);
|
||||
this.nbPages = Math.ceil((nrows - start_row) / this.pagingLength);
|
||||
|
||||
//Paging elements events
|
||||
var o = this;
|
||||
// Paging DOM events
|
||||
this.evt = {
|
||||
slcIndex(){
|
||||
return (o.pageSelectorType===tf.fltTypeSlc) ?
|
||||
slcIndex() {
|
||||
return (o.pageSelectorType === tf.fltTypeSlc) ?
|
||||
o.pagingSlc.options.selectedIndex :
|
||||
parseInt(o.pagingSlc.value, 10)-1;
|
||||
parseInt(o.pagingSlc.value, 10) - 1;
|
||||
},
|
||||
nbOpts(){
|
||||
return (o.pageSelectorType===tf.fltTypeSlc) ?
|
||||
parseInt(o.pagingSlc.options.length, 10)-1 :
|
||||
(o.nbPages-1);
|
||||
nbOpts() {
|
||||
return (o.pageSelectorType === tf.fltTypeSlc) ?
|
||||
parseInt(o.pagingSlc.options.length, 10) - 1 :
|
||||
(o.nbPages - 1);
|
||||
},
|
||||
next(){
|
||||
next() {
|
||||
var nextIndex = o.evt.slcIndex() < o.evt.nbOpts() ?
|
||||
o.evt.slcIndex()+1 : 0;
|
||||
o.evt.slcIndex() + 1 : 0;
|
||||
o.changePage(nextIndex);
|
||||
},
|
||||
prev(){
|
||||
var prevIndex = o.evt.slcIndex()>0 ?
|
||||
o.evt.slcIndex()-1 : o.evt.nbOpts();
|
||||
prev() {
|
||||
var prevIndex = o.evt.slcIndex() > 0 ?
|
||||
o.evt.slcIndex() - 1 : o.evt.nbOpts();
|
||||
o.changePage(prevIndex);
|
||||
},
|
||||
last(){
|
||||
last() {
|
||||
o.changePage(o.evt.nbOpts());
|
||||
},
|
||||
first(){
|
||||
first() {
|
||||
o.changePage(0);
|
||||
},
|
||||
_detectKey(e){
|
||||
_detectKey(e) {
|
||||
var key = Event.keyCode(e);
|
||||
if(key===13){
|
||||
if(tf.sorted){
|
||||
if (key === 13) {
|
||||
if (tf.sorted) {
|
||||
tf.filter();
|
||||
o.changePage(o.evt.slcIndex());
|
||||
} else{
|
||||
} else {
|
||||
o.changePage();
|
||||
}
|
||||
this.blur();
|
||||
|
|
@ -178,19 +178,19 @@ export class Paging extends Feature{
|
|||
/**
|
||||
* Initialize DOM elements
|
||||
*/
|
||||
init(){
|
||||
init() {
|
||||
var slcPages;
|
||||
var tf = this.tf;
|
||||
var evt = this.evt;
|
||||
|
||||
if(this.initialized){
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check resultsPerPage is in expected format and initialise the
|
||||
// results per page component
|
||||
if(this.hasResultsPerPage){
|
||||
if(this.resultsPerPage.length<2){
|
||||
if (this.hasResultsPerPage) {
|
||||
if (this.resultsPerPage.length < 2) {
|
||||
this.hasResultsPerPage = false;
|
||||
} else {
|
||||
this.pagingLength = this.resultsPerPage[1][0];
|
||||
|
|
@ -204,18 +204,18 @@ export class Paging extends Feature{
|
|||
};
|
||||
|
||||
// Paging drop-down list selector
|
||||
if(this.pageSelectorType === tf.fltTypeSlc){
|
||||
if (this.pageSelectorType === tf.fltTypeSlc) {
|
||||
slcPages = Dom.create(
|
||||
tf.fltTypeSlc, ['id', this.prfxSlcPages+tf.id]);
|
||||
tf.fltTypeSlc, ['id', this.prfxSlcPages + tf.id]);
|
||||
slcPages.className = this.pgSlcCssClass;
|
||||
Event.add(slcPages, 'change', evt.slcPagesChange);
|
||||
}
|
||||
|
||||
// Paging input selector
|
||||
if(this.pageSelectorType === tf.fltTypeInp){
|
||||
if (this.pageSelectorType === tf.fltTypeInp) {
|
||||
slcPages = Dom.create(
|
||||
tf.fltTypeInp,
|
||||
['id', this.prfxSlcPages+tf.id],
|
||||
['id', this.prfxSlcPages + tf.id],
|
||||
['value', this.currentPageNb]
|
||||
);
|
||||
slcPages.className = this.pgInpCssClass;
|
||||
|
|
@ -224,20 +224,20 @@ export class Paging extends Feature{
|
|||
|
||||
// btns containers
|
||||
var btnNextSpan = Dom.create(
|
||||
'span',['id', this.prfxBtnNextSpan+tf.id]);
|
||||
'span', ['id', this.prfxBtnNextSpan + tf.id]);
|
||||
var btnPrevSpan = Dom.create(
|
||||
'span',['id', this.prfxBtnPrevSpan+tf.id]);
|
||||
'span', ['id', this.prfxBtnPrevSpan + tf.id]);
|
||||
var btnLastSpan = Dom.create(
|
||||
'span',['id', this.prfxBtnLastSpan+tf.id]);
|
||||
'span', ['id', this.prfxBtnLastSpan + tf.id]);
|
||||
var btnFirstSpan = Dom.create(
|
||||
'span',['id', this.prfxBtnFirstSpan+tf.id]);
|
||||
'span', ['id', this.prfxBtnFirstSpan + tf.id]);
|
||||
|
||||
if(this.hasPagingBtns){
|
||||
if (this.hasPagingBtns) {
|
||||
// Next button
|
||||
if(!this.btnNextPageHtml){
|
||||
if (!this.btnNextPageHtml) {
|
||||
var btn_next = Dom.create(
|
||||
tf.fltTypeInp,
|
||||
['id', this.prfxBtnNext+tf.id],
|
||||
['id', this.prfxBtnNext + tf.id],
|
||||
['type', 'button'],
|
||||
['value', this.btnNextPageText],
|
||||
['title', 'Next']
|
||||
|
|
@ -250,10 +250,10 @@ export class Paging extends Feature{
|
|||
Event.add(btnNextSpan, 'click', evt.next);
|
||||
}
|
||||
// Previous button
|
||||
if(!this.btnPrevPageHtml){
|
||||
if (!this.btnPrevPageHtml) {
|
||||
var btn_prev = Dom.create(
|
||||
tf.fltTypeInp,
|
||||
['id', this.prfxBtnPrev+tf.id],
|
||||
['id', this.prfxBtnPrev + tf.id],
|
||||
['type', 'button'],
|
||||
['value', this.btnPrevPageText],
|
||||
['title', 'Previous']
|
||||
|
|
@ -266,10 +266,10 @@ export class Paging extends Feature{
|
|||
Event.add(btnPrevSpan, 'click', evt.prev);
|
||||
}
|
||||
// Last button
|
||||
if(!this.btnLastPageHtml){
|
||||
if (!this.btnLastPageHtml) {
|
||||
var btn_last = Dom.create(
|
||||
tf.fltTypeInp,
|
||||
['id', this.prfxBtnLast+tf.id],
|
||||
['id', this.prfxBtnLast + tf.id],
|
||||
['type', 'button'],
|
||||
['value', this.btnLastPageText],
|
||||
['title', 'Last']
|
||||
|
|
@ -282,10 +282,10 @@ export class Paging extends Feature{
|
|||
Event.add(btnLastSpan, 'click', evt.last);
|
||||
}
|
||||
// First button
|
||||
if(!this.btnFirstPageHtml){
|
||||
if (!this.btnFirstPageHtml) {
|
||||
var btn_first = Dom.create(
|
||||
tf.fltTypeInp,
|
||||
['id', this.prfxBtnFirst+tf.id],
|
||||
['id', this.prfxBtnFirst + tf.id],
|
||||
['type', 'button'],
|
||||
['value', this.btnFirstPageText],
|
||||
['title', 'First']
|
||||
|
|
@ -300,7 +300,7 @@ export class Paging extends Feature{
|
|||
}
|
||||
|
||||
// paging elements (buttons+drop-down list) are added to defined element
|
||||
if(!this.pagingTgtId){
|
||||
if (!this.pagingTgtId) {
|
||||
tf.setToolbar();
|
||||
}
|
||||
var targetEl = !this.pagingTgtId ? tf.mDiv : Dom.id(this.pagingTgtId);
|
||||
|
|
@ -308,34 +308,32 @@ export class Paging extends Feature{
|
|||
targetEl.appendChild(btnPrevSpan);
|
||||
|
||||
var pgBeforeSpan = Dom.create(
|
||||
'span',['id', this.prfxPgBeforeSpan+tf.id] );
|
||||
pgBeforeSpan.appendChild( Dom.text(this.pageText) );
|
||||
'span', ['id', this.prfxPgBeforeSpan + tf.id]);
|
||||
pgBeforeSpan.appendChild(Dom.text(this.pageText));
|
||||
pgBeforeSpan.className = this.nbPgSpanCssClass;
|
||||
targetEl.appendChild(pgBeforeSpan);
|
||||
targetEl.appendChild(slcPages);
|
||||
var pgAfterSpan = Dom.create(
|
||||
'span',['id', this.prfxPgAfterSpan+tf.id]);
|
||||
pgAfterSpan.appendChild( Dom.text(this.ofText) );
|
||||
'span', ['id', this.prfxPgAfterSpan + tf.id]);
|
||||
pgAfterSpan.appendChild(Dom.text(this.ofText));
|
||||
pgAfterSpan.className = this.nbPgSpanCssClass;
|
||||
targetEl.appendChild(pgAfterSpan);
|
||||
var pgspan = Dom.create( 'span',['id', this.prfxPgSpan+tf.id] );
|
||||
var pgspan = Dom.create('span', ['id', this.prfxPgSpan + tf.id]);
|
||||
pgspan.className = this.nbPgSpanCssClass;
|
||||
pgspan.appendChild( Dom.text(' '+this.nbPages+' ') );
|
||||
pgspan.appendChild(Dom.text(' ' + this.nbPages + ' '));
|
||||
targetEl.appendChild(pgspan);
|
||||
targetEl.appendChild(btnNextSpan);
|
||||
targetEl.appendChild(btnLastSpan);
|
||||
this.pagingSlc = Dom.id(this.prfxSlcPages+tf.id);
|
||||
this.pagingSlc = Dom.id(this.prfxSlcPages + tf.id);
|
||||
|
||||
if(!tf.rememberGridValues){
|
||||
this.setPagingInfo();
|
||||
}
|
||||
if(!tf.fltGrid){
|
||||
this.setPagingInfo();
|
||||
|
||||
if (!tf.fltGrid) {
|
||||
tf.validateAllRows();
|
||||
this.setPagingInfo(tf.validRowsIndex);
|
||||
}
|
||||
|
||||
this.emitter.on(['after-filtering'], ()=> this.resetPagingInfo());
|
||||
this.emitter.on(['initialized'], ()=> this.resetValues());
|
||||
this.emitter.on(['after-filtering'], () => this.resetPagingInfo());
|
||||
this.emitter.on(['change-page'],
|
||||
(tf, pageNumber) => this.setPage(pageNumber));
|
||||
this.emitter.on(['change-page-results'],
|
||||
|
|
@ -348,15 +346,15 @@ export class Paging extends Feature{
|
|||
* Reset paging when filters are already instantiated
|
||||
* @param {Boolean} filterTable Execute filtering once paging instanciated
|
||||
*/
|
||||
reset(filterTable=false){
|
||||
reset(filterTable = false) {
|
||||
var tf = this.tf;
|
||||
if(this.isEnabled()){
|
||||
if (this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
this.enable();
|
||||
this.init();
|
||||
|
||||
if(filterTable){
|
||||
if (filterTable) {
|
||||
tf.filter();
|
||||
}
|
||||
}
|
||||
|
|
@ -364,7 +362,7 @@ export class Paging extends Feature{
|
|||
/**
|
||||
* Reset paging info from scratch after a filtering process
|
||||
*/
|
||||
resetPagingInfo(){
|
||||
resetPagingInfo() {
|
||||
this.startPagingRow = 0;
|
||||
this.currentPageNb = 1;
|
||||
this.setPagingInfo(this.tf.validRowsIndex);
|
||||
|
|
@ -375,31 +373,32 @@ export class Paging extends Feature{
|
|||
* Refresh paging select according to number of pages
|
||||
* @param {Array} validRows Collection of valid rows
|
||||
*/
|
||||
setPagingInfo(validRows){
|
||||
setPagingInfo(validRows) {
|
||||
var tf = this.tf;
|
||||
var mdiv = !this.pagingTgtId ? tf.mDiv : Dom.id(this.pagingTgtId);
|
||||
var pgspan = Dom.id(this.prfxPgSpan+tf.id);
|
||||
var pgspan = Dom.id(this.prfxPgSpan + tf.id);
|
||||
|
||||
//store valid rows indexes
|
||||
tf.validRowsIndex = validRows || tf.getValidRows(true);
|
||||
|
||||
//calculate nb of pages
|
||||
this.nbPages = Math.ceil(tf.validRowsIndex.length/this.pagingLength);
|
||||
this.nbPages = Math.ceil(tf.validRowsIndex.length / this.pagingLength);
|
||||
//refresh page nb span
|
||||
pgspan.innerHTML = this.nbPages;
|
||||
//select clearing shortcut
|
||||
if(this.pageSelectorType === tf.fltTypeSlc){
|
||||
if (this.pageSelectorType === tf.fltTypeSlc) {
|
||||
this.pagingSlc.innerHTML = '';
|
||||
}
|
||||
|
||||
if(this.nbPages>0){
|
||||
if (this.nbPages > 0) {
|
||||
mdiv.style.visibility = 'visible';
|
||||
if(this.pageSelectorType === tf.fltTypeSlc){
|
||||
for(var z=0; z<this.nbPages; z++){
|
||||
var opt = Dom.createOpt(z+1, z*this.pagingLength, false);
|
||||
if (this.pageSelectorType === tf.fltTypeSlc) {
|
||||
for (var z = 0; z < this.nbPages; z++) {
|
||||
var opt = Dom.createOpt(z + 1, z * this.pagingLength,
|
||||
false);
|
||||
this.pagingSlc.options[z] = opt;
|
||||
}
|
||||
} else{
|
||||
} else {
|
||||
//input type
|
||||
this.pagingSlc.value = this.currentPageNb;
|
||||
}
|
||||
|
|
@ -415,26 +414,27 @@ export class Paging extends Feature{
|
|||
* Group table rows by page and display valid rows
|
||||
* @param {Array} validRows Collection of valid rows
|
||||
*/
|
||||
groupByPage(validRows){
|
||||
groupByPage(validRows) {
|
||||
var tf = this.tf;
|
||||
var rows = tf.tbl.rows;
|
||||
var startPagingRow = parseInt(this.startPagingRow, 10);
|
||||
var endPagingRow = startPagingRow + parseInt(this.pagingLength, 10);
|
||||
|
||||
//store valid rows indexes
|
||||
if(validRows){
|
||||
if (validRows) {
|
||||
tf.validRowsIndex = validRows;
|
||||
}
|
||||
|
||||
//this loop shows valid rows of current page
|
||||
for(var h=0, len=tf.validRowsIndex.length; h<len; h++){
|
||||
for (var h = 0, len = tf.validRowsIndex.length; h < len; h++) {
|
||||
var validRowIdx = tf.validRowsIndex[h];
|
||||
var r = rows[validRowIdx];
|
||||
var isRowValid = r.getAttribute('validRow');
|
||||
var rowDisplayed = false;
|
||||
|
||||
if(h>=startPagingRow && h<endPagingRow){
|
||||
if(Types.isNull(isRowValid) || Boolean(isRowValid==='true')){
|
||||
if (h >= startPagingRow && h < endPagingRow) {
|
||||
if (Types.isNull(isRowValid) ||
|
||||
Boolean(isRowValid === 'true')) {
|
||||
r.style.display = '';
|
||||
rowDisplayed = true;
|
||||
}
|
||||
|
|
@ -454,24 +454,24 @@ export class Paging extends Feature{
|
|||
* Return the current page number
|
||||
* @return {Number} Page number
|
||||
*/
|
||||
getPage(){
|
||||
getPage() {
|
||||
return this.currentPageNb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show page based on passed param value (string or number):
|
||||
* Show page defined by passed argument (string or number):
|
||||
* @param {String}/{Number} cmd possible string values: 'next',
|
||||
* 'previous', 'last', 'first' or page number as per param
|
||||
*/
|
||||
setPage(cmd){
|
||||
setPage(cmd) {
|
||||
var tf = this.tf;
|
||||
if(!tf.hasGrid() || !this.isEnabled()){
|
||||
if (!tf.hasGrid() || !this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
var btnEvt = this.evt,
|
||||
cmdtype = typeof cmd;
|
||||
if(cmdtype === 'string'){
|
||||
switch(Str.lower(cmd)){
|
||||
if (cmdtype === 'string') {
|
||||
switch (Str.lower(cmd)) {
|
||||
case 'next':
|
||||
btnEvt.next();
|
||||
break;
|
||||
|
|
@ -489,19 +489,19 @@ export class Paging extends Feature{
|
|||
break;
|
||||
}
|
||||
}
|
||||
else if(cmdtype === 'number'){
|
||||
this.changePage(cmd-1);
|
||||
else if (cmdtype === 'number') {
|
||||
this.changePage(cmd - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates UI elements for the number of results per page drop-down
|
||||
*/
|
||||
setResultsPerPage(){
|
||||
setResultsPerPage() {
|
||||
var tf = this.tf;
|
||||
var evt = this.evt;
|
||||
|
||||
if(this.resultsPerPageSlc || !this.resultsPerPage){
|
||||
if (this.resultsPerPageSlc || !this.resultsPerPage) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -511,16 +511,16 @@ export class Paging extends Feature{
|
|||
};
|
||||
|
||||
var slcR = Dom.create(
|
||||
tf.fltTypeSlc, ['id', this.prfxSlcResults+tf.id]);
|
||||
tf.fltTypeSlc, ['id', this.prfxSlcResults + tf.id]);
|
||||
slcR.className = this.resultsSlcCssClass;
|
||||
var slcRText = this.resultsPerPage[0],
|
||||
slcROpts = this.resultsPerPage[1];
|
||||
var slcRSpan = Dom.create(
|
||||
'span',['id', this.prfxSlcResultsTxt+tf.id]);
|
||||
'span', ['id', this.prfxSlcResultsTxt + tf.id]);
|
||||
slcRSpan.className = this.resultsSpanCssClass;
|
||||
|
||||
// results per page select is added to external element
|
||||
if(!this.resultsPerPageTgtId){
|
||||
if (!this.resultsPerPageTgtId) {
|
||||
tf.setToolbar();
|
||||
}
|
||||
var targetEl = !this.resultsPerPageTgtId ?
|
||||
|
|
@ -528,7 +528,7 @@ export class Paging extends Feature{
|
|||
slcRSpan.appendChild(Dom.text(slcRText));
|
||||
|
||||
var help = tf.feature('help');
|
||||
if(help && help.btn){
|
||||
if (help && help.btn) {
|
||||
help.btn.parentNode.insertBefore(slcRSpan, help.btn);
|
||||
help.btn.parentNode.insertBefore(slcR, help.btn);
|
||||
} else {
|
||||
|
|
@ -536,7 +536,7 @@ export class Paging extends Feature{
|
|||
targetEl.appendChild(slcR);
|
||||
}
|
||||
|
||||
for(var r=0; r<slcROpts.length; r++){
|
||||
for (var r = 0; r < slcROpts.length; r++) {
|
||||
var currOpt = new Option(slcROpts[r], slcROpts[r], false, false);
|
||||
slcR.options[r] = currOpt;
|
||||
}
|
||||
|
|
@ -547,17 +547,17 @@ export class Paging extends Feature{
|
|||
/**
|
||||
* Remove number of results per page UI elements
|
||||
*/
|
||||
removeResultsPerPage(){
|
||||
removeResultsPerPage() {
|
||||
var tf = this.tf;
|
||||
if(!tf.hasGrid() || !this.resultsPerPageSlc || !this.resultsPerPage){
|
||||
if (!tf.hasGrid() || !this.resultsPerPageSlc || !this.resultsPerPage) {
|
||||
return;
|
||||
}
|
||||
var slcR = this.resultsPerPageSlc,
|
||||
slcRSpan = Dom.id(this.prfxSlcResultsTxt+tf.id);
|
||||
if(slcR){
|
||||
slcRSpan = Dom.id(this.prfxSlcResultsTxt + tf.id);
|
||||
if (slcR) {
|
||||
Dom.remove(slcR);
|
||||
}
|
||||
if(slcRSpan){
|
||||
if (slcRSpan) {
|
||||
Dom.remove(slcRSpan);
|
||||
}
|
||||
this.resultsPerPageSlc = null;
|
||||
|
|
@ -567,36 +567,36 @@ export class Paging extends Feature{
|
|||
* Change the page according to passed index
|
||||
* @param {Number} index Index of the page (0-n)
|
||||
*/
|
||||
changePage(index){
|
||||
changePage(index) {
|
||||
var tf = this.tf;
|
||||
|
||||
if(!this.isEnabled()){
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.emitter.emit('before-page-change', tf, (index + 1));
|
||||
|
||||
if(index === null){
|
||||
if (index === null) {
|
||||
index = this.pageSelectorType === tf.fltTypeSlc ?
|
||||
this.pagingSlc.options.selectedIndex : (this.pagingSlc.value-1);
|
||||
this.pagingSlc.options.selectedIndex : this.pagingSlc.value - 1;
|
||||
}
|
||||
if( index>=0 && index<=(this.nbPages-1) ){
|
||||
if(this.onBeforeChangePage){
|
||||
if (index >= 0 && index <= (this.nbPages - 1)) {
|
||||
if (this.onBeforeChangePage) {
|
||||
this.onBeforeChangePage.call(null, this, (index + 1));
|
||||
}
|
||||
this.currentPageNb = parseInt(index, 10)+1;
|
||||
if(this.pageSelectorType===tf.fltTypeSlc){
|
||||
this.currentPageNb = parseInt(index, 10) + 1;
|
||||
if (this.pageSelectorType === tf.fltTypeSlc) {
|
||||
this.pagingSlc.options[index].selected = true;
|
||||
} else {
|
||||
this.pagingSlc.value = this.currentPageNb;
|
||||
}
|
||||
|
||||
this.startPagingRow = (this.pageSelectorType === tf.fltTypeSlc) ?
|
||||
this.pagingSlc.value : (index*this.pagingLength);
|
||||
this.pagingSlc.value : (index * this.pagingLength);
|
||||
|
||||
this.groupByPage();
|
||||
|
||||
if(this.onAfterChangePage){
|
||||
if (this.onAfterChangePage) {
|
||||
this.onAfterChangePage.call(null, this, (index + 1));
|
||||
}
|
||||
}
|
||||
|
|
@ -604,8 +604,8 @@ export class Paging extends Feature{
|
|||
this.emitter.emit('after-page-change', tf, (index + 1));
|
||||
}
|
||||
|
||||
changeResultsPerPage(val){
|
||||
if(!this.isEnabled() || isNaN(val)){
|
||||
changeResultsPerPage(val) {
|
||||
if (!this.isEnabled() || isNaN(val)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -616,10 +616,10 @@ export class Paging extends Feature{
|
|||
/**
|
||||
* Change rows according to page results drop-down
|
||||
*/
|
||||
onChangeResultsPerPage(){
|
||||
onChangeResultsPerPage() {
|
||||
var tf = this.tf;
|
||||
|
||||
if(!this.isEnabled()){
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -628,21 +628,21 @@ export class Paging extends Feature{
|
|||
var slcR = this.resultsPerPageSlc;
|
||||
var slcIndex = slcR.selectedIndex;
|
||||
var slcPagesSelIndex = (this.pageSelectorType === tf.fltTypeSlc) ?
|
||||
this.pagingSlc.selectedIndex :
|
||||
parseInt(this.pagingSlc.value-1, 10);
|
||||
this.pagingSlc.selectedIndex :
|
||||
parseInt(this.pagingSlc.value - 1, 10);
|
||||
this.pagingLength = parseInt(slcR.options[slcIndex].value, 10);
|
||||
this.startPagingRow = this.pagingLength*slcPagesSelIndex;
|
||||
this.startPagingRow = this.pagingLength * slcPagesSelIndex;
|
||||
|
||||
if(!isNaN(this.pagingLength)){
|
||||
if(this.startPagingRow >= tf.nbFilterableRows){
|
||||
this.startPagingRow = (tf.nbFilterableRows-this.pagingLength);
|
||||
if (!isNaN(this.pagingLength)) {
|
||||
if (this.startPagingRow >= tf.nbFilterableRows) {
|
||||
this.startPagingRow = (tf.nbFilterableRows - this.pagingLength);
|
||||
}
|
||||
this.setPagingInfo();
|
||||
|
||||
if(this.pageSelectorType === tf.fltTypeSlc){
|
||||
if (this.pageSelectorType === tf.fltTypeSlc) {
|
||||
var slcIdx =
|
||||
(this.pagingSlc.options.length-1<=slcPagesSelIndex) ?
|
||||
(this.pagingSlc.options.length-1) : slcPagesSelIndex;
|
||||
(this.pagingSlc.options.length - 1 <= slcPagesSelIndex) ?
|
||||
(this.pagingSlc.options.length - 1) : slcPagesSelIndex;
|
||||
this.pagingSlc.options[slcIdx].selected = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -650,31 +650,18 @@ export class Paging extends Feature{
|
|||
this.emitter.emit('after-page-length-change', tf, this.pagingLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-set persisted pagination info
|
||||
*/
|
||||
resetValues(){
|
||||
var tf = this.tf;
|
||||
if(tf.rememberPageLen){
|
||||
this.resetPageLength();
|
||||
}
|
||||
if(tf.rememberPageNb){
|
||||
this.resetPage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-set page nb at page re-load
|
||||
*/
|
||||
resetPage(){
|
||||
resetPage() {
|
||||
var tf = this.tf;
|
||||
if(!this.isEnabled()){
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
this.emitter.emit('before-reset-page', tf);
|
||||
var pgNb = tf.feature('store').getPageNb();
|
||||
if(pgNb !== ''){
|
||||
this.changePage((pgNb-1));
|
||||
if (pgNb !== '') {
|
||||
this.changePage((pgNb - 1));
|
||||
}
|
||||
this.emitter.emit('after-reset-page', tf, pgNb);
|
||||
}
|
||||
|
|
@ -682,15 +669,15 @@ export class Paging extends Feature{
|
|||
/**
|
||||
* Re-set page length value at page re-load
|
||||
*/
|
||||
resetPageLength(){
|
||||
resetPageLength() {
|
||||
var tf = this.tf;
|
||||
if(!this.isEnabled()){
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
this.emitter.emit('before-reset-page-length', tf);
|
||||
var pglenIndex = tf.feature('store').getPageLength();
|
||||
|
||||
if(pglenIndex!==''){
|
||||
if (pglenIndex !== '') {
|
||||
this.resultsPerPageSlc.options[pglenIndex].selected = true;
|
||||
this.changeResultsPerPage();
|
||||
}
|
||||
|
|
@ -700,74 +687,73 @@ export class Paging extends Feature{
|
|||
/**
|
||||
* Remove paging feature
|
||||
*/
|
||||
destroy(){
|
||||
destroy() {
|
||||
var tf = this.tf;
|
||||
|
||||
if(!this.initialized){
|
||||
if (!this.initialized) {
|
||||
return;
|
||||
}
|
||||
// btns containers
|
||||
var btnNextSpan = Dom.id(this.prfxBtnNextSpan+tf.id);
|
||||
var btnPrevSpan = Dom.id(this.prfxBtnPrevSpan+tf.id);
|
||||
var btnLastSpan = Dom.id(this.prfxBtnLastSpan+tf.id);
|
||||
var btnFirstSpan = Dom.id(this.prfxBtnFirstSpan+tf.id);
|
||||
var btnNextSpan = Dom.id(this.prfxBtnNextSpan + tf.id);
|
||||
var btnPrevSpan = Dom.id(this.prfxBtnPrevSpan + tf.id);
|
||||
var btnLastSpan = Dom.id(this.prfxBtnLastSpan + tf.id);
|
||||
var btnFirstSpan = Dom.id(this.prfxBtnFirstSpan + tf.id);
|
||||
//span containing 'Page' text
|
||||
var pgBeforeSpan = Dom.id(this.prfxPgBeforeSpan+tf.id);
|
||||
var pgBeforeSpan = Dom.id(this.prfxPgBeforeSpan + tf.id);
|
||||
//span containing 'of' text
|
||||
var pgAfterSpan = Dom.id(this.prfxPgAfterSpan+tf.id);
|
||||
var pgAfterSpan = Dom.id(this.prfxPgAfterSpan + tf.id);
|
||||
//span containing nb of pages
|
||||
var pgspan = Dom.id(this.prfxPgSpan+tf.id);
|
||||
var pgspan = Dom.id(this.prfxPgSpan + tf.id);
|
||||
|
||||
var evt = this.evt;
|
||||
|
||||
if(this.pagingSlc){
|
||||
if(this.pageSelectorType === tf.fltTypeSlc){
|
||||
if (this.pagingSlc) {
|
||||
if (this.pageSelectorType === tf.fltTypeSlc) {
|
||||
Event.remove(this.pagingSlc, 'change', evt.slcPagesChange);
|
||||
}
|
||||
else if(this.pageSelectorType === tf.fltTypeInp){
|
||||
else if (this.pageSelectorType === tf.fltTypeInp) {
|
||||
Event.remove(this.pagingSlc, 'keypress', evt._detectKey);
|
||||
}
|
||||
Dom.remove(this.pagingSlc);
|
||||
}
|
||||
|
||||
if(btnNextSpan){
|
||||
if (btnNextSpan) {
|
||||
Event.remove(btnNextSpan, 'click', evt.next);
|
||||
Dom.remove(btnNextSpan);
|
||||
}
|
||||
|
||||
if(btnPrevSpan){
|
||||
if (btnPrevSpan) {
|
||||
Event.remove(btnPrevSpan, 'click', evt.prev);
|
||||
Dom.remove(btnPrevSpan);
|
||||
}
|
||||
|
||||
if(btnLastSpan){
|
||||
if (btnLastSpan) {
|
||||
Event.remove(btnLastSpan, 'click', evt.last);
|
||||
Dom.remove(btnLastSpan);
|
||||
}
|
||||
|
||||
if(btnFirstSpan){
|
||||
if (btnFirstSpan) {
|
||||
Event.remove(btnFirstSpan, 'click', evt.first);
|
||||
Dom.remove(btnFirstSpan);
|
||||
}
|
||||
|
||||
if(pgBeforeSpan){
|
||||
if (pgBeforeSpan) {
|
||||
Dom.remove(pgBeforeSpan);
|
||||
}
|
||||
|
||||
if(pgAfterSpan){
|
||||
if (pgAfterSpan) {
|
||||
Dom.remove(pgAfterSpan);
|
||||
}
|
||||
|
||||
if(pgspan){
|
||||
if (pgspan) {
|
||||
Dom.remove(pgspan);
|
||||
}
|
||||
|
||||
if(this.hasResultsPerPage){
|
||||
if (this.hasResultsPerPage) {
|
||||
this.removeResultsPerPage();
|
||||
}
|
||||
|
||||
this.emitter.off(['after-filtering'], ()=> this.resetPagingInfo());
|
||||
this.emitter.off(['initialized'], ()=> this.resetValues());
|
||||
this.emitter.off(['after-filtering'], () => this.resetPagingInfo());
|
||||
this.emitter.off(['change-page'],
|
||||
(tf, pageNumber) => this.setPage(pageNumber));
|
||||
this.emitter.off(['change-page-results'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue