How to edit the default message (There are no items to show in this view) on an empty list-view webpart

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/245321

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";}
许可以下: CC-BY-SA归因
scroll top