gpt4 book ai didi

javascript - 使用 JSLink Sharepoint 过滤数据

转载 作者:行者123 更新时间:2023-11-30 16:53:00 26 4
gpt4 key购买 nike

我使用 JSLink 自定义 SharePoint 显示列表。

我成功过滤了数据,您可以在以下链接中看到:

https://sharepoint.stackexchange.com/questions/91317/filter-out-items-in-list-view-using-jslink

当我点击列标题尝试第二次过滤数据时,它会系统地带回所有旧数据,而不是整理之前过滤的数据。

最佳答案

在提供的示例中,过滤器按行索引应用,这解释了为什么在应用排序前后显示不同的行。

下面的示例演示了如何通过列表项 id 隐藏行,在这种情况下,过滤器将一致地应用于相同的行:

(function () {

function listPreRender(renderCtx) {

var excludeItemIds = [1]; //hide list item with Id=1

var rows = renderCtx.ListData.Row; //get current rows
var filteredRows = rows.filter(function(row){
var curItemId = parseInt(row.ID);
if(excludeItemIds.indexOf(curItemId) === -1)
return row;
});

renderCtx.ListData.Row = filteredRows;
renderCtx.ListData.LastRow = filteredRows.length; //update ListData.LastRow property
}


function registerListRenderer()
{
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
Templates : {
OnPreRender : listPreRender
}
});
}
ExecuteOrDelayUntilScriptLoaded(registerListRenderer, 'clienttemplates.js');

})();

结果

过滤后的 ListView

enter image description here

应用排序后的过滤 ListView

enter image description here

关于javascript - 使用 JSLink Sharepoint 过滤数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30208486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com