2017-08-23 16 views
0

我有一点点的jQuery我添加到一个SharePoint页面,为列表中的几个表格单元格着色。当页面加载时,它完美地工作,但是当列表被过滤时,代码停止。在列表过滤后,我需要做些什么才能使其工作?简单的jQuery在SharePoint 2013列表停​​止工作后过滤

$(document).ready(function(){ 
$('table.red').closest('td').addClass('redBG'); 
$('.yellow').closest('td').addClass('yellowBG'); 

});

回答

1

为此使用SharePoint客户端侧渲染。 这里来自PnP的一些教程:https://github.com/SharePoint/PnP/tree/dev/Samples/Branding.ClientSideRendering 但你也可以搜索谷歌。

代码:

(function() { 
    if (typeof SPClientTemplates === 'undefined') 
     return; 
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides({ 
     OnPostRender: [ 
      function (ctx) { DoStuff(ctx); }, 
     ] 
    }); 
})(); 

function DoStuff(ctx) { 
    $('table.red').closest('td').addClass('redBG'); 
    $('.yellow').closest('td').addClass('yellowBG'); 
} 

以此作为外部js文件,并添加链接到显示您的列表数据上ListViewWebPart的JSLINK属性的文件。您的OnPostRender函数将触发过滤和分页。

+0

非常感谢!这真的有诀窍。 –