Search code examples
sapui5

how to add column to table in controller with bindAggregation ui5


 I have created value help

What I want is to add another column of quantity Adding it to columns is not a problem because it's total JSON But putting it in rows is a bit problematic - because I pull the data from the table - the products - they have no quantity. I want to create this here by invitation The point is that the code is in the form of oTable.bindAggregation

here is my valuhelp this is my code:

onValueHelpRequested: function() {
    var aCols = this.oColModel.getData().cols;
    this._oValueHelpDialog = sap.ui.xmlfragment("Ztest.Ztest.view.ValueHelpDialogBasic", this);
    this.getView().addDependent(this._oValueHelpDialog);

    this._oValueHelpDialog.getTableAsync().then(function (oTable) {
        oTable.setModel(window.orders);
        oTable.setModel(this.oColModel, "columns");

        if (oTable.bindRows) {
            oTable.bindAggregation("rows", "/Items");
        }

        if (oTable.bindItems) {
            oTable.bindAggregation("items", "/Items", function () {
                return new ColumnListItem({
                    cells: aCols.map(function (column) {
                        return new Label({ text: "{" + column.template + "}" });
                    })
                });
            });
        }
        this._oValueHelpDialog.update();
    }.bind(this));

    this._oValueHelpDialog.setTokens(this._oMultiInput.getTokens());
    this._oValueHelpDialog.open();
},

have I a control here to insert step input into each row? I mean such a thing like: what mind input step


Solution

  • because it Unable to log in second if if (oTable.bindItems) pereps because oTable.setModel(this.oColModel, "columns"); I made it as

    `onValueHelpRequested: function() {
                var aCols = this.oColModel.getData().cols;
                this._oValueHelpDialog = sap.ui.xmlfragment("Ztest.Ztest.view.ValueHelpDialogBasic", this);
                this.getView().addDependent(this._oValueHelpDialog);
    
                this._oValueHelpDialog.getTableAsync().then(function (oTable) {
                    oTable.setModel(window.orders);
                    oTable.setModel(this.oColModel, "columns");
                     var oColumn = new sap.ui.table.Column({
                            label: new sap.m.Label({text: "Qty"}),
                            template: new sap.m.StepInput({value: "{Qty}"}),
                            width: "70px",
                            step:"1",
                            largerStep:"1",
                            max:"35",
                            min:"0",
                            stepMode:"Multiple" 
                    });
    
                    if (oTable.bindRows){
                        oTable.addColumn(oColumn);
                        oTable.bindAggregation("rows", "/Items");
                    }
    
                    /*if (oTable.bindItems) {
                            oTable.bindAggregation("items", "/Items", function () {
                            return new ColumnListItem({
                                     cells: aCols.map(function (column) {
                                     console.log(column);
                                        if (column.template=="Qty") {
                                            return new StepInput({ text: "{" + column.template + "}" });
                                        } else {
                                            return new Label({ text: "{" + column.template + "}" });
                                        }
                                    })
                            });
                        });
                    }*/
                    this._oValueHelpDialog.update();
                }.bind(this));
    
                this._oValueHelpDialog.setTokens(this._oMultiInput.getTokens());
                this._oValueHelpDialog.open();
            },
    

    `