Notice: Firmware Links Under Maintenance We are currently undergoing maintenance on all firmware links. If any links are inaccessible, please email or contact Tech Support for the firmware. We appreciate your patience during the maintenance, thank you for your understanding.

Difference between revisions of "User:JP/common.js"

Line 5: Line 5:
 
});
 
});
 
});
 
});
 +
var tfConfig = {
 +
        base_path: 'tablefilter/',
 +
        alternate_rows: true,
 +
        btn_reset: true,
 +
        rows_counter: true,
 +
        loader: true,
 +
        status_bar: true,
 +
        paging: true,
 +
        col_0: 'select',
 +
        col_1: 'select',
 +
        col_2: 'select',
 +
        extensions:[{
 +
            name: 'sort',
 +
            types: [
 +
                'string', 'string', 'number',
 +
                'number', 'number', 'number',
 +
                'number', 'number', 'number'
 +
            ]
 +
        }]
 +
    };
 +
    var tf = new TableFilter(document.querySelector('#demo'), tfConfig);
 +
 +
    // Subscribe to events
 +
    // Format cell at initialization
 +
    tf.emitter.on(['initialized'], parseRows);
 +
    // Format cell upon filtering
 +
    tf.emitter.on(['cell-processed'], formatCell);
 +
 +
    tf.init();
 +
 +
    // Process all rows on start-up
 +
    function parseRows(tf){
 +
        var cellIndex = 3; // POP column
 +
        var rowsIdx = tf.getValidRows();
 +
        rowsIdx.forEach(function(idx){
 +
            var row = tf.tbl.rows[idx];
 +
            var cell = row.cells[cellIndex];
 +
            formatCell(tf, cellIndex, cell);
 +
        });
 +
    }
 +
 +
    // Format passed cell with custom logic
 +
    function formatCell(tf, cellIndex, cell){
 +
        if(cellIndex !== 3){
 +
            return;
 +
        }
 +
        var cellData = parseInt(cell.innerHTML, 10);
 +
 +
        // some rows do not contain a numeric value
 +
        if(isNaN(cellData)){
 +
            return;
 +
        }
 +
 +
        if(cellData >= 100000){
 +
            cell.style.backgroundColor = '#ff0000';
 +
        } else if(cellData < 100000 && cellData >= 50000) {
 +
            cell.style.backgroundColor = '#3399ff';
 +
        } else {
 +
            cell.style.backgroundColor = '#cfff33';
 +
        }
 +
    }

Revision as of 17:37, 3 August 2016

$(function(){
	importArticles({
		type: "script",
		articles: ["u:pad.wikia.com:MediaWiki:FilterTable.js"]
	});
});
 var tfConfig = {
        base_path: 'tablefilter/',
        alternate_rows: true,
        btn_reset: true,
        rows_counter: true,
        loader: true,
        status_bar: true,
        paging: true,
        col_0: 'select',
        col_1: 'select',
        col_2: 'select',
        extensions:[{
            name: 'sort',
            types: [
                'string', 'string', 'number',
                'number', 'number', 'number',
                'number', 'number', 'number'
            ]
        }]
    };
    var tf = new TableFilter(document.querySelector('#demo'), tfConfig);

    // Subscribe to events
    // Format cell at initialization
    tf.emitter.on(['initialized'], parseRows);
    // Format cell upon filtering
    tf.emitter.on(['cell-processed'], formatCell);

    tf.init();

    // Process all rows on start-up
    function parseRows(tf){
        var cellIndex = 3; // POP column
        var rowsIdx = tf.getValidRows();
        rowsIdx.forEach(function(idx){
            var row = tf.tbl.rows[idx];
            var cell = row.cells[cellIndex];
            formatCell(tf, cellIndex, cell);
        });
    }

    // Format passed cell with custom logic
    function formatCell(tf, cellIndex, cell){
        if(cellIndex !== 3){
            return;
        }
        var cellData = parseInt(cell.innerHTML, 10);

        // some rows do not contain a numeric value
        if(isNaN(cellData)){
            return;
        }

        if(cellData >= 100000){
            cell.style.backgroundColor = '#ff0000';
        } else if(cellData < 100000 && cellData >= 50000) {
            cell.style.backgroundColor = '#3399ff';
        } else {
            cell.style.backgroundColor = '#cfff33';
        }
    }