I have 3 list webparts on my home page. I've used this script to hide 2 columns on page load and changes (sorting, filtering).
// Override list views to hide language columns based on locale
listOverride: {
set: function () {
var overrideCurrentContext = {};
overrideCurrentContext.Templates = {};
overrideCurrentContext.OnPostRender = listOverride.hideLanguageColumns;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);
},
hideLanguageColumns: function () {
// Loop through columns which need to be hidden and hide from view
cca.locale.hiddenLangColumns.map(function (column) {
// Get column position
var columnIndex = $("tr.ms-viewheadertr th:contains('" + column + "')").first().index() + 1;
// Find and Hide column
$('th:nth-child(' + columnIndex + '),td:nth-child(' + columnIndex + ')').hide();
})
console.log("list post render done")
}
},
I'm experiencing two problems:
- The CSR do not do anything on page load. I need to call listOverride.hideLanguageColumns explicitly on page load for it to take effect.
- When I upload documents through drag n drop, the row Cells for the columns I've hidden are displayed again for the new item, but the columns are still hidden so I've got a table now with less columns then row cells.
I'm a bit stuck on both issues.