Here is the rowspan replacement script I used (it is written in Javascript and uses jQuery)
The reverse() bit is needed to preserve order - the script uses prepend to insert new elements so we have to start with the last element that needs work and finish with the first.
function replace_rowspan(section){
$.fn.reverse = [].reverse; //http://forum.jquery.com/topic/jquery-reverse-a-collection-of-jquery-elements
//script to process an array containing rowspan and re-write it without rowspan by putting in all the repeats
while($(section).find("td[rowspan]").length>0){ //are there any rowspans left
$(section).find("tr>td[rowspan]:first").each(function(i,tdi){ //find a row with a rowspan
var the_row=$(tdi).parents("tr");
$(the_row).find("td[rowspan]").reverse().each(function(j,tdj){
var c=$(tdj).clone();
var rs=$(tdj).attr("rowspan")-1;
var v=$(tdj).text();
$(tdj).removeAttr("rowspan");
if(rs>=2) //if the rowspan left is 2 or more, then leave the rowspan attribute in and let it be processed next time round
$(the_row).next().prepend($(c).attr("rowspan",rs).addClass("green") );
else if(rs==1) // otherwise this will be the last new entry and the rowspan attribute can be removed
$(the_row).next().prepend($(c).removeAttr("rowspan").addClass("red") );
})
})
}
}
No comments:
Post a Comment