Friday, November 4, 2011

How to 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 of IE or Firbug of Firefox.
Get Column ID using Developer tool of IE

2. Add following JavaScript in HTML form web part on the list view.
<script type="text/javascript">
//This script is developed by Amit Phule # http://amitphule.blogspot.com/
 _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:


Live simple !

3 comments:

  1. If Creted By column is present twice in a page.Then it is not reflecting the new name in the second place
    RenameColumn('diidSortAuthor', 'Author');

    ReplyDelete
  2. Hi Amid, how do I find the id of projected column of exetrnal content type?
    I need to rename the column name from "MatterNo: REL_MATTER" to "REL_MATTER".
    Thank you

    ReplyDelete
  3. Thanks for this. It really helped.But I id from internet explorer and other browser are different from each other. cant it just have same id for the field in all the browser..

    ReplyDelete