Monday 30 July 2012

Hide List columns in EditForm & DisplayForm at RunTime


Scenario 1:
If the Administrator does not want to allow end users to see all columns in default EditForm or DisplayForm of a list then he can hide the specific columns from end users by using the following script

<script type="text/javascript">
$(document).ready(function(){
     $('nobr:contains("Column-Name1")').closest('tr').hide();
     $('nobr:contains("Column-Name2")').closest('tr').hide();
});</script>

where Column-Name1is the name of the column within the list which the administrator wants to hide.

Scenario 2:
If the Administrator wants to hide certain columns based on the value of other column within the list from end users in default EditForm or DisplayForm of a list then he can hide the specific columns by using the following script

<script type="text/javascript">
$(document).ready(function(){
     var DropDownStatus = $("[title='Status']").val();
     if(DropDownStatus == "Pending")
     {
         $('nobr:contains("ColumnToHide")').closest('tr').hide();
     }
});</script>



where,

ColumnToHide is the name of the column within the list which the administrator wants to hide.

 var DropDownStatus = $("[title='Status']").val(); - fetches the value of the column name "Status" & assigns it to variable DropDownStatus.



No comments:

Post a Comment