DEV Community

KIranuknow
KIranuknow

Posted on

1

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

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

typescript

11 Tips That Make You a Better Typescript Programmer

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

πŸ‘‹ Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay