使用 CSR 從 SharePoint 列表檢視隱藏列
此示例顯示如何使用 CSR 從 SharePoint 列表檢視中隱藏日期欄位。
(function () {
function RemoveFields(ctx) {
var fieldName = "Date"; // here Date is field or column name to be hide
var header = document.querySelectorAll("[displayname=" + fieldName + "]")[0].parentNode;
var index = [].slice.call(header.parentNode.children).indexOf(header) + 1;
header.style.display = "none";
for (var i = 0, cells = document.querySelectorAll("td:nth-child(" + index + ")"); i < cells.length; i++) {
cells[i].style.display = "none";
}
}
function registerRenderer() {
var ctxForm = {};
ctxForm.Templates = {};
ctxForm.OnPostRender = RemoveFields;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
}
ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');
})();