Created
August 16, 2012 17:07
-
-
Save ekka21/3371726 to your computer and use it in GitHub Desktop.
Javascript: fix column table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @Desc: Convert str1,str2,str3,str4,str5,....... to fix table columns | |
// @Param: String, delimiter, number_col | |
// @Return: Table markup - fixed columns | |
function prep_table(str,del,numCols){ | |
var cnt = 0; | |
var arr = str.split(del); | |
var loop = arr.length; | |
var out_str = "<table width='100%'>"; | |
for (cnt=0; cnt<loop; cnt++) | |
{ | |
if (cnt % numCols == 0) | |
{ | |
if (cnt > 0) | |
{ | |
out_str += "</tr>"; | |
} | |
out_str += "<td valign='top'>"; | |
} | |
out_str += "<td>"+arr[cnt]+"</td>"; | |
}//end forloop | |
while (cnt % numCols != 0) | |
{ | |
out_str += "<td> </td>"; | |
cnt++; | |
} | |
out_str += "</tr></table>"; | |
return out_str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment