Dear all
If you want to change the sharepoint column name only in view the following script will work perfectly
<script>
(function () {
function preTaskFormRenderer(renderCtx) {
modifyColumns(renderCtx);
}
function modifyColumns(renderCtx)
{
var arrayLength= renderCtx.ListSchema.Field.length;
for (var i=0; i < arrayLength;i++)
{
if(renderCtx.ListSchema.Field[i].DisplayName == '[Your Comlumn Name 1]')
{
var newTitle= "[New Name]";
var linkTitleField = renderCtx.ListSchema.Field[i];
linkTitleField.DisplayName = newTitle;
}
if(renderCtx.ListSchema.Field[i].DisplayName == ''[Your Comlumn Name 2]')
{
var newTitle= "[New Name]";
var linkTitleField = renderCtx.ListSchema.Field[i];
linkTitleField.DisplayName = newTitle;
}
}
}
function registerRenderer()
{
var ctxForm = {};
ctxForm.Templates = {};
ctxForm.OnPreRender = preTaskFormRenderer;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
}
ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');
})();
</script>
If you want to change the sharepoint column name only in view the following script will work perfectly
<script>
(function () {
function preTaskFormRenderer(renderCtx) {
modifyColumns(renderCtx);
}
function modifyColumns(renderCtx)
{
var arrayLength= renderCtx.ListSchema.Field.length;
for (var i=0; i < arrayLength;i++)
{
if(renderCtx.ListSchema.Field[i].DisplayName == '[Your Comlumn Name 1]')
{
var newTitle= "[New Name]";
var linkTitleField = renderCtx.ListSchema.Field[i];
linkTitleField.DisplayName = newTitle;
}
if(renderCtx.ListSchema.Field[i].DisplayName == ''[Your Comlumn Name 2]')
{
var newTitle= "[New Name]";
var linkTitleField = renderCtx.ListSchema.Field[i];
linkTitleField.DisplayName = newTitle;
}
}
}
function registerRenderer()
{
var ctxForm = {};
ctxForm.Templates = {};
ctxForm.OnPreRender = preTaskFormRenderer;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
}
ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');
})();
</script>
How to use it
step 1. Edit page
step 2. Click on insert tab
step 3. Click on embed code option (last one)
step 4. Copy and past the above JS code
Note change the column name with your names and define the new name as required
The above method is already tested method
All right, you are correct buddy. The way you've explained how to change the header column name or title in SharePoint view is just awesome. I also visit some other blog for this but I doesn't found any comprehensive post like this, You've made it more easy to understand.
ReplyDeleteThe Best Medical Marketing Strategies for Doctors in America.