开发者

Hide a column in display(view form) in Sharepoint 2007 using JQUERY

I am trying to hide a column in Sharepoint 2007 using Jquery. The code I am working to hide columns

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script type="text/javascript">
ColumnsToHide = new Array();
ColumnsToHide[0]='First Name';
ColumnsToHide[1]='Last Name'; 

$(document).ready(function()
{
 for (var i=0; i < ColumnsToHide.length;i++)
 {
  QueryString='nobr:contains("' + ColumnsToHide[i] + '")';
  $(QueryString).hide().parents('tr:first').hide();
 }
});
</script>

I even tried to hide column using various code

1 $('nobr:contains("First Name")').closest('tr').hide();

2$(":input[title='First Name']").parent().parent().hide();

3 $("#ms-formbody").hide();

4 $('input[title=First Name]').parent().parent().parent().hide();

By using above ways I couldn't able to hide columns. Could guide me through it since I am newbie to Jquery

I am also providing source code, I want column to be hidden when page loads in Display form of sharepoint 2007

<TR>
<TD nowrap="true" valign="top" width="165px" class="ms-formlabel"><H3 class="ms-standardheader"><a name="SPBookmark_FirstName"></a>First Name</H3></TD>
        <TD valign="top" class="ms-formbody" width="450px" ID="SPFieldText">
        <!-- FieldName="First Name"
             FieldInternalName="FirstName"
             FieldType="SPFieldText"
          --></TD>  </TR>

<TR>
<TD nowrap="true" valign="top" width="165px" class="ms-formlabel"><H3 class="ms-standardheader"><a name="SPBookmark_MiddleName"></a>Middle Name</H3></TD>
        <TD valign="top" class="ms-formbody" width="450px" ID="SPFieldText">
        <!-- FieldName="Middle Name"
             开发者_如何学PythonFieldInternalName="MiddleName"
             FieldType="SPFieldText"
          --></TD></TR>


This will hide a field on a form:

var label = "TextArea1";
$(".ms-formtable input[Title='"+ label +"']").closest("tr").hide();

This will hide a column in a view:

var colName = "TextArea1";
var index = $("tr.ms-viewheadertr th:contains('"+ colName +"')").index();
$("tr.ms-viewheadertr th:contains('"+ colName +"')").hide();
$("table.ms-listviewtable tbody").first().find("tr").each(function(){
    $(this).find("td:nth-child("+ index +")").hide();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜