Naveen
Naveen

Reputation: 777

How to select all checkbox in sap UI5

XML

<columns>
    <Column width="3em">
    <CheckBox select="selectAll"/>
</Column>
<items/>

JS

var table = this.getView().byId("Table");
table.bindItems({
    path: "/",
    template: new sap.m.ColumnListItem({
        cells: [
            new sap.m.CheckBox({
                name: "{ue_connection_name}",
                selected: "{enabled}",
                enabled: true
            }),

        ]
    })
});

selectAll: function() {
 this.selected = true;
}

Here I have few checkbox list. When I click main checkbox in table header, I want to select all other check boxes. How to select all checkboxes in sapUI5

Upvotes: 1

Views: 7113

Answers (1)

Rahul Bhardwaj
Rahul Bhardwaj

Reputation: 2353

Please try the below code:

I've mentioned the comments to explain better.

selectAll: function(oEvent) {
        var otab = this.byId("idTab"); // Fetch the table

        var bSelected = oEvent.getParameter('selected'); // fetch whether user selected/de-selected all

        otab.getItems().forEach(function(item) { // loop over all the items in the table
            var oCheckBoxCell = item.getCells()[0]; //fetch the cell which holds the checkbox for that row.

            oCheckBoxCell.setSelected(bSelected); // Select/de-select each checkbox
        });
    }

Please comment if you need more information.

Upvotes: 5

Related Questions