SAPUI5 - Hiding a table column? [closed]

微笑、不失礼 提交于 2020-01-07 09:50:06

问题


I have a a table rendered from an xml view.

Is there a way I can hide an entire column in the controller?


回答1:


For the record, there are two Table controls in SAPUI5: sap.m.Table and sap.ui.table.Table

For both you can set the visible property of a Column to false to hide that Column.

oTable.getColumns()[i].setVisible(false)

Edit: Additional requirement from the comment:

To get the table in the Controller, use the Controller's byId function with the id of the Table:

this.byId("tableId").getColumns()[i].setVisible(false)

(Given that this is the Controller instance.)




回答2:


Just stumbled over this Q in search for something else. The more elegant way to solve your problem would be to create a model and a property for each column.

var oVisModel = new JSONModel({
            row1: "true",
            row2: "true"
});
this.setModel(oVisModel, "visModel");

Since JSONModels bind 2 way you now can bind the visible property in your XML

<m:Column
        id="row1"
        visible="{visModel>/row1}"
        minScreenWidth=""
        demandPopin="false">
        <m:Text text="{i18n>row1}" />
</m:Column>

If you now want to change the visibility in your controller you can smth like this:

//if model is bound to component.js
this.getOwnerComponent().getModel("visModel").setProperty("/row1", "false");

//if model is bound to App.controller.js or how ever your main view controller is named
this.getView().getModel("visModel").setProperty("/row1", "false");

Even though the answer is kind of late, i hope it helps ppl who find this at a later point.

Regards, Eric




回答3:


Solution was this:

view.byId("DefaultTimesTable").getColumns()[4].setVisible(false)


来源:https://stackoverflow.com/questions/36427141/sapui5-hiding-a-table-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!