SAPUI5 oTable one row as a link, others as textvie

2020-04-17 06:59发布

Currently I have an sapui table, where I want to have one single row being a link, all other rows should be textviews. my problem is, that constructing the table is based on columns:

oTable.addColumn(new sap.ui.table.Column({
    label : new sap.ui.commons.Label({
        text : "Berichtsmonat",
        hAlign : sap.ui.core.HorizontalAlign.Center,
    }),
    template : new sap.ui.commons.Link({ // <-- this should only be valid
                 // for one row, others should be
                 // new sap.ui.commons.TextView
        text : "{Text01}",
        press : pressListOpen, 
    }),
    width : '120px',
    hAlign : sap.ui.core.HorizontalAlign.Center,
}));

later after defining all columns..

oTable.bindRows("/GetXYZ");

So, I cannot switch this for one single line. How would I do this? is it possible?

I think I have to create the table in another way, but how? Would be very thankful for code examples how to solve the problem or how to construct the table properly for my doing...

1条回答
小情绪 Triste *
2楼-- · 2020-04-17 07:34

One solution is that you define the template as a HorizontalLayout. Add additional visibility flags to your existing data model, for example as following VisibleFlagForText and VisibleFlagForLink (VisibleFlagForText == !VisibleFlagForLink) .

var oText = new sap.ui.commons.TextView({
    text:"{Text01}", 
    visible : "{VisibleFlagForText}"
});

var oLink = new sap.ui.commons.Link({ 
    text : "{Text01}",
    press : pressListOpen, 
    visible : "{VisibleFlagForLink}"
});

var oLayout = new sap.ui.layout.HorizontalLayout("Layout1",{content: [oText, oLink ]});

oTable.addColumn(new sap.ui.table.Column({
    label : new sap.ui.commons.Label({
        text : "Berichtsmonat",
        hAlign : sap.ui.core.HorizontalAlign.Center,
    }),
    template : oLayout,
    width : '120px',
    hAlign : sap.ui.core.HorizontalAlign.Center,
}));

Then you can update the visibility flags of the data model of your single row to set link visible or textview visible.

查看更多
登录 后发表回答