Skip to content

Instantly share code, notes, and snippets.

@ekka21
Created August 16, 2012 17:07
Show Gist options
  • Save ekka21/3371726 to your computer and use it in GitHub Desktop.
Save ekka21/3371726 to your computer and use it in GitHub Desktop.
Javascript: fix column table
// @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>&nbsp;</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