1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2026-03-16 23:55:46 +01:00

Initial commit

This commit is contained in:
Max Guglielmi 2015-11-15 02:14:13 +11:00
commit dcb271e0ba
41 changed files with 9616 additions and 653 deletions

View file

@ -1,29 +1,31 @@
import {Feature} from './feature';
import Dom from '../dom';
export class AlternateRows{
export class AlternateRows extends Feature {
/**
* Alternating rows color
* @param {Object} tf TableFilter instance
*/
constructor(tf) {
var f = tf.config();
//defines css class for even rows
this.evenCss = f.even_row_css_class || 'even';
//defines css class for odd rows
this.oddCss = f.odd_row_css_class || 'odd';
super(tf, 'alternateRows');
this.tf = tf;
var config = this.config;
//defines css class for even rows
this.evenCss = config.even_row_css_class || 'even';
//defines css class for odd rows
this.oddCss = config.odd_row_css_class || 'odd';
}
/**
* Sets alternating rows color
*/
init() {
var tf = this.tf;
if(!tf.hasGrid() && !tf.isFirstLoad){
if(this.initialized){
return;
}
var tf = this.tf;
var validRowsIndex = tf.validRowsIndex;
var noValidRowsIndex = validRowsIndex===null;
//1st index
@ -40,6 +42,7 @@ export class AlternateRows{
this.setRowBg(rowIdx, idx);
idx++;
}
this.initialized = true;
}
/**
@ -49,7 +52,7 @@ export class AlternateRows{
* color
*/
setRowBg(rowIdx, idx) {
if(!this.tf.alternateBgs || isNaN(rowIdx)){
if(!this.isEnabled() || isNaN(rowIdx)){
return;
}
var rows = this.tf.tbl.rows;
@ -78,22 +81,15 @@ export class AlternateRows{
/**
* Removes all alternating backgrounds
*/
remove() {
destroy() {
if(!this.tf.hasGrid()){
return;
}
for(var i=this.tf.refRow; i<this.tf.nbRows; i++){
this.removeRowBg(i);
}
}
enable() {
this.tf.alternateBgs = true;
}
disable() {
this.tf.alternateBgs = false;
this.disable();
this.initialized = false;
}
}

42
src/modules/feature.js Normal file
View file

@ -0,0 +1,42 @@
const NOTIMPLEMENTED = 'Not implemented.';
export class Feature {
constructor(tf, feature) {
this.tf = tf;
this.feature = feature;
this.enabled = this.tf[feature];
this.config = tf.config();
this.initialized = false;
}
init() {
throw new Error(NOTIMPLEMENTED);
}
reset() {
if(!this.tf.hasGrid()){
return;
}
this.enable();
this.init();
}
destroy() {
throw new Error(NOTIMPLEMENTED);
}
enable() {
this.enabled = true;
this.tf[this.feature] = this.enabled;
}
disable() {
this.enabled = false;
this.tf[this.feature] = this.enabled;
}
isEnabled() {
return this.enabled;
}
}

View file

@ -1,17 +1,20 @@
import {Feature} from './feature';
import Dom from '../dom';
import Types from '../types';
import Str from '../string';
import Event from '../event';
export class Paging{
export class Paging extends Feature{
/**
* Pagination component
* @param {Object} tf TableFilter instance
*/
constructor(tf){
super(tf, 'paging');
// Configuration object
var f = tf.config();
var f = this.config;
//css class for paging buttons (previous,next,etc.)
this.btnPageCssClass = f.paging_btn_css_class || 'pgInp';
@ -170,8 +173,6 @@ export class Paging{
lastEvt: null,
firstEvt: null
};
this.tf = tf;
}
/**
@ -182,6 +183,10 @@ export class Paging{
var tf = this.tf;
var evt = this.evt;
if(this.initialized){
return;
}
// Check resultsPerPage is in expected format and initialise the
// results per page component
if(this.hasResultsPerPage){
@ -321,7 +326,7 @@ export class Paging{
targetEl.appendChild(btnLastSpan);
this.pagingSlc = Dom.id(this.prfxSlcPages+tf.id);
if(!tf.rememberGridValues || this.isPagingRemoved){
if(!tf.rememberGridValues){
this.setPagingInfo();
}
if(!tf.fltGrid){
@ -329,7 +334,7 @@ export class Paging{
this.setPagingInfo(tf.validRowsIndex);
}
this.isPagingRemoved = false;
this.initialized = true;
}
/**
@ -338,11 +343,10 @@ export class Paging{
*/
reset(filterTable=false){
var tf = this.tf;
if(!tf.hasGrid() || tf.paging){
if(!tf.hasGrid() || this.isEnabled()){
return;
}
tf.paging = true;
this.isPagingRemoved = true;
this.enable();
this.init();
tf.resetValues();
if(filterTable){
@ -433,12 +437,12 @@ export class Paging{
if(Types.isNull(isRowValid) || Boolean(isRowValid==='true')){
r.style.display = '';
}
if(tf.alternateBgs && alternateRows){
if(tf.alternateRows && alternateRows){
alternateRows.setRowBg(validRowIdx, h);
}
} else {
r.style.display = 'none';
if(tf.alternateBgs && alternateRows){
if(tf.alternateRows && alternateRows){
alternateRows.removeRowBg(validRowIdx);
}
}
@ -464,7 +468,7 @@ export class Paging{
*/
setPage(cmd){
var tf = this.tf;
if(!tf.hasGrid() || !tf.paging){
if(!tf.hasGrid() || !this.isEnabled()){
return;
}
var btnEvt = this.evt,
@ -609,7 +613,7 @@ export class Paging{
_changePage(index){
var tf = this.tf;
if(!tf.paging){
if(!this.isEnabled()){
return;
}
if(index === null){
@ -648,7 +652,7 @@ export class Paging{
_changeResultsPerPage(){
var tf = this.tf;
if(!tf.paging){
if(!this.isEnabled()){
return;
}
var slcR = this.resultsPerPageSlc;
@ -692,7 +696,7 @@ export class Paging{
*/
_resetPageLength(name){
var tf = this.tf;
if(!tf.paging){
if(!this.isEnabled()){
return;
}
var pglenIndex = tf.feature('store').getPageLength(name);
@ -774,7 +778,7 @@ export class Paging{
this.pagingSlc = null;
this.nbPages = 0;
this.isPagingRemoved = true;
tf.paging = false;
this.disable();
this.initialized = false;
}
}

View file

@ -1,15 +1,18 @@
import {Feature} from './feature';
import Dom from '../dom';
import Types from '../types';
export class RowsCounter{
export class RowsCounter extends Feature{
/**
* Rows counter
* @param {Object} tf TableFilter instance
*/
constructor(tf){
super(tf, 'rowsCounter');
// TableFilter configuration
var f = tf.config();
var f = this.config;
//id of custom container element
this.rowsCounterTgtId = f.rows_counter_target_id || null;
@ -40,12 +43,12 @@ export class RowsCounter{
}
init(){
var tf = this.tf;
if((!tf.hasGrid() && !tf.isFirstLoad) || this.rowsCounterSpan){
if(this.initialized){
return;
}
var tf = this.tf;
//rows counter container
var countDiv = Dom.create('div', ['id', this.prfxCounter+tf.id]);
countDiv.className = this.totRowsCssClass;
@ -75,6 +78,7 @@ export class RowsCounter{
this.rowsCounterDiv = countDiv;
this.rowsCounterSpan = countSpan;
this.initialized = true;
this.refresh();
}
@ -131,5 +135,7 @@ export class RowsCounter{
}
this.rowsCounterSpan = null;
this.rowsCounterDiv = null;
this.disable();
this.initialized = false;
}
}