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帰属
所属していません sharepoint.stackexchange
scroll top