SAPUI5 - Typescript

kiranuknow

KIranuknow

Posted on July 23, 2024

SAPUI5 - Typescript

To dynamically add columns to a sap.ui.table.Table in SAPUI5 using TypeScript, you can follow these steps: Create a new column object.

import Column from "sap/ui/table/Column";
import Label from "sap/m/Label";
import Text from "sap/m/Text";

// ...

const newColumn = new Column({
    label: new Label({ text: "New Column" }), // Column header
    template: new Text({ text: "{propertyName}" }), // Binding to a property in your model
    width: "100px" // Optional width setting
});

Enter fullscreen mode Exit fullscreen mode

Add the column to the table.

const myTable = this.byId("myTable") as sap.ui.table.Table;
myTable.addColumn(newColumn);
Enter fullscreen mode Exit fullscreen mode

Example:

import Controller from "sap/ui/core/mvc/Controller";
import Column from "sap/ui/table/Column";
import Label from "sap/m/Label";
import Text from "sap/m/Text";

export default class MyController extends Controller {

    onAddColumn() {
        const newColumn = new Column({
            label: new Label({ text: "Dynamic Column" }),
            template: new Text({ text: "{myProperty}" }),
            width: "150px"
        });

        const myTable = this.byId("myTable") as sap.ui.table.Table;
        myTable.addColumn(newColumn);
    }
}





Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
kiranuknow
KIranuknow

Posted on July 23, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

SAPUI5 - Typescript
sapui5 SAPUI5 - Typescript

July 23, 2024