vendredi 9 août 2019

Binding checkboxes in smart table to boolean from oData (CDS view)

I have generated an oData service from a CDS view. The isAssigned property is of type Edm.boolean and I would like to bind it to a column of checkboxes in a SmartTable.

I have tried setting the table to multiple select mode and add a lineItem annotation to the CDS but the field just showed as a text of "Yes" or "No".

My most recent attempt was to add a custom column with a SmartField. According to the documentation a smartfield should automatically become a checkbox if bound to a boolean which does not seem to happen. I tried adding a Configuration to it with ControlType Checkbox in the xml which resulted in an error (see below). I also tried to set the configuration for the SmartField through the controller and the result was still a "Yes" or "No" column.

View

    <smartTable:SmartTable id="smartTable" entitySet="<set>"
 height="100%" smartFilterId="filterBar">
    <Table>
        <columns>
            <Column>
                <header>
                    <Text text="Assigned" />
                </header>
            </Column>
        </columns>
        <items>
            <ColumnListItem>
                <cells>
                    <smartField:SmartField 
                         id="smartAssignField" entitySet="<set>" 
                         value="{isAssigned}">
                            <configuration>
                                <smartField:Configuration 
                                 controlType="checkBox" />
                            </configuration>
                        </smartField:SmartField>
                    </cells>
                </ColumnListItem>
            </items>
        </Table>
    </smartTable:SmartTable>

Controller

onInit: function() {
this.byId("smartTable").attachBeforeRebindTable(this.setFieldType.bind(this))
},
setFieldType: function(oEvent) {
       var smartField = this.byId("smartAssignField");
       smartField.setConfiguration(
           new sap.ui.comp.smartfield.Configuration({controlType: "checkBox" }));
}

When trying to configure through view I get the error "XMLTemplateProcessor-dbg.js:887 Uncaught (in promise) Error: Cannot add direct child without default aggregation defined for control sap.ui.comp.smartfield.SmartField at l1 (XMLTemplateProcessor-dbg.js:887)" twice. When setting from the controller the column still appears as a text of "Yes" or "No".

Thank you,

Ben




Aucun commentaire:

Enregistrer un commentaire