LightSwitch HTML 客户端 (VS2013 Update 4) - 如何以编程方式隐藏列



示例:我们有一个客户的可视化集合,客户有 3 个字段 ID、Name 和 FavoriteFood,它们都绑定到表中的列,但在运行时我们可能需要根据其他一些逻辑的结果隐藏 FavoriteFood 列。

我已经能够在列(如FavoriteFood_postRender)甚至行模板(RowTemplate1_postRender)上执行_postRender,并为contentItem切换isVisible = false以使特定的表格单元格(td元素)不显示,但在这两种情况下,表格标题(th)单元格仍然存在。

黑客的解决方法是做类似 $('th:nth-child(3),td:nth-child(3)').hide() 之类的操作,尽管你需要足够晚才能真正工作(例如,表的 postRender 发生在集合仍然为空时,并且 th 元素存在,但 td 元素还没有,所以你可以在那里做 th 隐藏, 但是您需要 contentItem.dataBind 在 td 单元格上执行 N 个不同的隐藏,这有点丑陋),但我试图找出是否有办法通过内容项隐藏列,因为它们都有 isVisible 并且似乎是隐藏事物的正确方法。

谢谢!

对于遇到

此问题的其他人,我无法使用isVisible和类似的LightSwitch模型属性找出编程方法,因此基本上做了一些类似于问题状态的事情。 我想我可以将每对组合成 1 行,"td:nth-child(4),th:nth-child(4)",但这对我来说已经足够了。

.hideColumn4               td:nth-child(4)   { display:none !important; } 
.hideColumn4               th:nth-child(4)   { display:none !important; } 
.hideColumn5               td:nth-child(5)   { display:none !important; } 
.hideColumn5               th:nth-child(5)   { display:none !important; } 
.hideColumn6               td:nth-child(6)   { display:none !important; } 
.hideColumn6               th:nth-child(6)   { display:none !important; } 

然后在表的 postRender 中,在弄清楚要隐藏哪些之后,我做了这样的事情:

if (conditionForHidingColumn4) {
    $(element).addClass('hideColumn4');
}

通过在表的 postRender 中执行此操作,我可以确保将这些类添加到我想要的表中,而不会影响任何其他表。

最新更新