问题
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