Question

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

Was it helpful?

Solution

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";}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top