Introduction

This blog shows how to convert the default table structure of newform and editform into a 2x2 matrix based table
Required JS File
  1. Latest jQuery library
  2. Latest SPUtility.js file from codeplex
Default New Form
Steps
  1. Open the Newform.aspx for a list and click on Edit Page
  2. Add a Content Editor Web part and add the <script src> for the above two JS files3.
  3. Add the below code snippet
  1. jQuery(document).ready(function() {
  2. TablifyFields("FirstName", "BusinessUnit");
  3. });
  4. function TablifyFields(fromField, toField)
  5. {
  6. jQuery(SPUtility.GetSPField(fromField).LabelRow).parent().css("display","block");
  7. var fromIndex = jQuery(SPUtility.GetSPField(fromField).LabelRow).index();
  8. var toIndex = jQuery(SPUtility.GetSPField(toField).LabelRow).index();
  9. var rowwidth = jQuery(SPUtility.GetSPField(fromField).LabelRow).parent().width();
  10. var trWidth = parseInt(rowwidth)/2 + "px";
  11. var tdwidth = jQuery(SPUtility.GetSPField(fromField).LabelRow).children().eq(0).width();
  12. var tdWidth = parseInt(rowwidth)/2 - parseInt(tdwidth);
  13. var tBody = jQuery(SPUtility.GetSPField(fromField).LabelRow).parent().children();
  14. jQuery.each(tBody,function(index, value){
  15. if(index >= fromIndex && index <=toIndex)
  16. {
  17. ModifyFieldPosition(value, trWidth, tdWidth);
  18. }
  19. });
  20. }
  21. function ModifyFieldPosition(fieldtr, trwidth, tdwidth)
  22. {
  23. jQuery(fieldtr).css("float","left");
  24. jQuery(fieldtr).css("width",trwidth);
  25. jQuery(fieldtr).children().eq(1).css("width",tdwidth+"px");
  26. var firsttdWidth = jQuery(fieldtr).children().eq(0).attr("width").replace("px","");
  27. var inputWidth = jQuery(fieldtr).children().eq(1).children().children().width();
  28. jQuery(fieldtr).children().eq(0).css("width",90/100*(parseInt(firsttdWidth))+"px");
  29. if(parseInt(inputWidth)>parseInt(tdwidth))
  30. {
  31. jQuery(fieldtr).children().eq(1).children().children().css("width",tdwidth+"px");
  32. }
  33. }
Voila ! Customized New Form: