Pages

Where it all started - Javascript

It all started when I started researching on Greasemonkey plugin, which gives you the flexibility to run JavaScript on any web page. Started trying sample scripts and it was cool. I started online learning javascript in code academy.  Code Academy is a free online compiler where the courses are framed in such a way you learn as you code. It has a very easy interface and they start from the scratch. Rather watching youtube tutorial videos this is far far better way to learn.

External Links:-
Codeacademy.com
http://jsfiddle.net

After few courses I was successfully able to modify a javascript snippet and make it work without any errors for my personal use. A simple HTML table filter. It will hide the row if it matches the value you enter. The code is as below


       

hideRowsWithLargeCellValue("/html/body/table/tbody/tr[", 80, "]/td[", "]");
function hideRowsWithLargeCellValue(xpathPre, maxRows, xpathPost, maxpi) {
for (var J = maxRows; J >= 1; --J) 
for(var i=1;i<=7;i++){
var srchRez = document.evaluate(xpathPre + J + xpathPost + i + maxpi, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (srchRez.singleNodeValue && srchRez.singleNodeValue.textContent == "1") {
var rowToHide = srchRez.singleNodeValue.parentNode;
rowToHide.style.display = 'none';
        }
    }
}

       
This was a snippet taken from google and is edited according to my requirement. The jsfiddle link will explain with html example. This script will filter out all the rows that has "1" in any of the cell. To check how it works change "textContent == "1"" to "textContent == "0""  you can observe the difference in the result window.
Jsfiddle link : - http://jsfiddle.net/aravindshadow/YeBL4/7/

No comments:

Post a Comment