Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

So I'm using the below formula to try to set my column widths for a column called title, but it doesn't seem to be working:

<!--ADJUST TABLE COLUMN WIDTH--><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script><script type="text/javascript">$(function(){$("TH.ms-vh2-nograd:contains('Title')").css("width", "150px"); $("TH.ms-vb:contains('Title')").css("width", "150px"); }); </script>

Believe this should be working, because when I view source, I see;

class="ms-vh2"div style="width:100%;position:relative;left:0;top:0;"TABLE style="width:100%;" Sortable="" SortDisable="" FilterDisable="" Filterable="" Name="LinkTitle" CtxNum="2" DisplayName="Title" FieldType="Computed" ResultType="" SortFields="SortField=LinkTitle&amp;SortDir=Asc&amp;View=%7bE2B0E597%2d8A06%2d4365%2dA48C%2d00B47A7CFE24%7d&amp;PageView=Shared" height="100%" cellspacing=1 cellpadding=0 class="ms-unselectedtitle"

PLEASE HELP!

share|improve this question
    
Rob, Did you ever get this to work? I have the same requirement, and tried your code above with no success. –  user2429 Feb 16 '11 at 17:09
    
Rob, when you say it's not working... what's it doing? Is the TH greater than or less than 150px? –  Jim Bob Howard Mar 10 '11 at 20:44
add comment

2 Answers

Original Comment: Want to try that again as a code sample?

Edit, with actualy Answer:

Thanks. That helps.

What I think you're running up against is that your jQuery is running before the page is finished loading. Try this:

<!--ADJUST TABLE COLUMN WIDTH-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">

  $(document).ready( function(){
      $("TH.ms-vh2-nograd:contains('Title')").css("width", "150px");
      $("TH.ms-vb:contains('Title')").css("width", "150px");
  });

</script>
share|improve this answer
add comment

Maybe you would do better to fetch the dynamic control id and work from there.

var $trackingGridID = $("[id$=_ListViewWebPartJSGrid_leftpane_mainTable]").attr("id");
$('#' + trackingGridID).css("background-color", "blue");

this will fetch this control id:

ctl00_ctl21_g_c3e5fead_d466_4448_9648_dcb92778921d_ListViewWebPartJSGrid_leftpane_mainTable

Here is my similar question with regards to column widths on a GANTT chart.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.