please remember this is just working example , you might need to write ALL-Browser compliant script .
script:
var filters=['hide_broj_pu','hide_naziv_pu','hide_ID','hide_naselje','hide_zupanija'];
functionExcludeRows(cls){
var skipRows=[];
for(i=0;i<filters.length;i++)
if(filters[i]!=cls) skipRows.push(filters[i]);
var pattern=skipRows.join('|')
return pattern;
}
functionFilter(srcField){
var node=srcField.parentNode;
var index=srcField.parentNode.cellIndex;
//all the DATA rowsvar dataRows= document.getElementsByClassName("row");
//ensure that dataRows do not have any filter class added alreadyvar kids= dataRows.length;
var filter ='hide_'+srcField.id;
var pattern = ExcludeRows(filter);
var skipRow = newRegExp(pattern,"gi");
var searchReg =newRegExp('^'+srcField.value,'gi');
var replaceCls= newRegExp(filter,'gi');
for(i=0; i< kids ; i++){
//skip if already filter applied if(dataRows[i].className.match(skipRow)) continue;
//now we know which column to search//remove current filter
dataRows[i].className=dataRows[i].className.replace(replaceCls,'');
if(!dataRows[i].cells[index].innerHTML.trim().match(searchReg))
dataRows[i].className=dataRows[i].className +' '+ filter;
}
}
Post a Comment for "Dynamically Filter Rows Of A Html Table Using Javascript"