Monday, 25 June 2012

Rename the list view column name using JavaScript

We can change column name from JavaScript, it will not affect your existing functionality or custom code and also no need to change column name from SharePoint Designer as it is a troublesome task.
Follow this steps….
1. Get column Id using Developer tool.

2. Add following JavaScript in Content Editor web part on the list view.
<script type="text/javascript">
//This script is developed by Mohammad Yusuf Hussain # http://mohammadyusufhussain-sharepoint.blogspot.in/
 _spBodyOnLoadFunctionNames.push("ChangeColumnName"); // Call ChangeColumnName function on PageLoad
        function ChangeColumnName()
          {
            RenameColumn('diidSortAuthor', 'Author'); //Provide Column ID and New Column name
        }
        function RenameColumn(colID, NewHeader) {
            try {
                document.getElementById(colID).innerHTML = NewHeader; //Change Header Name
                document.getElementById(colID).title = "Sort by " + NewHeader; // Change Tooltip value
            }
            catch (err) {
                alert('Invalid Column ID:' + colID);
            }
        }
 </script>
Old Column Name:


New Column Name:
 
 
 

4 comments:

  1. Thanks a lot... Nice post... it helped me a lot..

    ReplyDelete
  2. Thanks, that was very helpful.

    ReplyDelete
  3. I have multiple list view web parts on my page and it only changes the first one. How can I make this code change all list views with the name "ID"?

    ReplyDelete