Skip to content

Instantly share code, notes, and snippets.

@koohq
Created November 9, 2017 16:25
Show Gist options
  • Save koohq/5a74c768787e740f8b4adbad5dcd6a9d to your computer and use it in GitHub Desktop.
Save koohq/5a74c768787e740f8b4adbad5dcd6a9d to your computer and use it in GitHub Desktop.
Changing the display name of field on the SharePoint List view
/**
* sp-fielddisplaynamechanger.js
* Provides a function to create a function that changes the display name of field.
* The created function is use for JSLink on SharePoint list view pages.
*
* (c) 2017 koohq. Licensed under CC0.
* https://creativecommons.org/publicdomain/zero/1.0/legalcode
*/
var SPFieldDisplayNameChanger = (function() {
function create(nameMapping) {
return function changeFieldDisplayName(renderCtx) {
renderCtx.ListSchema.Field.forEach(function(field) {
var newName = nameMapping[field.Name];
(typeof newName !== 'undefined') && (field.DisplayName = newName);
});
};
}
return Object.freeze({
create: create
});
})();
/**
* sp-fielddisplaynamechanger.usage.js
*
* (c) 2017 koohq. Licensed under CC0.
* https://creativecommons.org/publicdomain/zero/1.0/legalcode
*/
ExecuteOrDelayUntilScriptLoaded(function() {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPreRender: SPFieldDisplayNameChanger.create({
'LinkTitle': 'AnotherTitle',
'_ModerationStatus': 'Status',
'Modified': 'LastWriteTime'
})
});
}, 'clienttemplates.js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment