Can i add a JS Link to a list view in modern interface
-
29-01-2021 - |
Question
I have the following JS link , which i have added to classic interface inside our sharepoint on-premises 2013:-
(function () {
function registerRenderer() {
var ctxForm = {};
ctxForm.Templates = {};
ctxForm.Templates = {
Fields : {
'LinkTitle': { //------ Change Hyperlink of LinkTitle
View : function (ctx) {
alert("123");
if(ctx.CurrentItem.SiteCreated != null && ctx.CurrentItem.SiteCreated === 'Yes'){
var url = String.format('{0}{1}', "/sites/projectmanagement/", ctx.CurrentItem.ID);
return String.format('<a href="{0}" onclick="EditItem2(event, \'{0}\');return false;">{1}</a>', url, ctx.CurrentItem.Title);
}
else
{
var url = String.format('{0}{1}', "/Lists/projects/DispForm.aspx?ID=", ctx.CurrentItem.ID);
return String.format('<a href="{0}" onclick="EditItem2(event, \'{0}\');return false;">{1}</a>', url, ctx.CurrentItem.Title);
}
}
},
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
}
ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');
})();
then i reference it as follow inside the list view:-
now the JS link will modify the item url base on a custom column value. When i migrated the site to sharepoint online, the JSLINK will work perfectly on classic interface, but if i switch to modern interface the JSLINK will not have any effect. so can anyone advice if i can use my JSLINK to have effect on modern interfaces in sharepoint online? if the answer is No, then what are the approaches i can follow to achieve this ?
Thanks
La solution
In SharePoint Online modern interface list view, the JSLINK will not works.
We can use the column formatting to achieve your requirement, the following official document for your reference.
Autres conseils
JSLink does not works on modern interface, it is default disabled. Microsoft is advising to migrate your JSLinks to SharePoint Framework Field Customizers/SharePoint Framework Extensions.
Microsoft has also published the article on their official documentation site. You may check here:
Migrating JSLink customizations to SharePoint Framework Field Customizers
Migrating from JSLink to SharePoint Framework Extensions
Going ahead all SharePoint Online customizations will be more SharePoint Framework centric.
An extract from above 1st article:
One of the main benefits of migrating old-school JSLink customizations to the SharePoint Framework is that it is the only supported technique that you have on modern sites for customizing the UI of "modern" lists and libraries. In fact, the "modern" lists and libraries, because of their rendering infrastructure and because of the no-script flag enabled on the "modern" sites, can't rely on old-school JSLink customizations. Thus, if you really want to extend the "modern" UI, you need to upgrade to the SharePoint Framework.