I have 3 separate list-view webparts on a page and I want to modify the default message when a list-view webpart is empty. But I only want to apply this on one of these 3 list-view webparts.

The code which I'm using is working fine. But it is affecting all of the webparts on the page.

<script> (function () {
var overrideCurrentContext = {};
overrideCurrentContext.Templates = {};
overrideCurrentContext.Templates.OnPreRender = changeNoListItemMessage; //OR overrideCurrentContext.OnPreRender = changeNoListItemMessage;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);})();function changeNoListItemMessage(ctx) {
ctx.ListSchema.NoListItem = "No data 01";}</script>

How can I apply this code on a single list-view webpart?

Thanks in advance


You can probably check for the list title or something since you have the context object.

So inside the "changeNoListItemMessage" function, put an if condition to check if the title matches

if(ctx.ListTitle == "Your list name")
{ctx.ListSchema.NoListItem = "No data 01";}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.