如何将焦点设置在sap.ui.table.Table中的Input字段上

时间:2017-01-24 13:25:34

标签: sap sapui5

我想将焦点设置在表格中一行的输入字段中。如何读取此行的ID并设置焦点?

for(var i = 0; i < rowCount; i++) {

   var oEntry = this.getView().getModel("items").getProperty(
   oTable.getContextByIndex(i).sPath);

   if (oEntry.Field1 === sField1){
      //Here I will set the focus in an Input field
   }
}

由于

编辑:

<columns>
    <Column width="2rem" sortProperty="Field">
        <m:Label text="{i18n>Field}" />
        <template>
            <m:CheckBox
                selected="{
                path: 'items>Field',
                type: 'sap.ui.model.type.String'
                }"
            editable="false" />
        </template>
    </Column>
    <Column width="6rem">
        <m:Label text="{i18n>Field1}" />
        <template>
            <m:Text text="{items>Field1}" />
        </template>
    </Column>
    <Column width="6rem">
        <m:Label text="{i18n>Field2}" />
        <template>
            <m:Input
                value="{items>Field2}" />
        </template>
    </Column>

这是视图中我的表的列:我想把焦点放在行上,其中Field1 = s.Field1。如何在特殊行中设置id?

编辑2.0:

XML视图:

<Column width="6rem">
    <m:Label text="{i18n>Field2}" />
    <template>
        <m:Input
            id="input2" value="{items>Field2}"/>
    </template>
</Column>

控制器:

for(var i = 0; i < rowCount; i++) {
    var oEntry = this.getView().getModel("items").getProperty(
                              oTable.getContextByIndex(i).sPath);
    if (oEntry.Field1 === sField1){
        this.getView().byId("input2").focus();

     }
}
this.getView().getModel("items").refresh(true);

2 个答案:

答案 0 :(得分:1)

您还可以执行以下操作:

var oTable = this.getView().byId("idTable");
var aRows = oTable.getRows();
for (var i = 0; i < aRows.length; i++) {
    if (aRows[i].getBindingContext().getObject().Field1 === sField1) {
        var oCell = aRows[i].getCells()[2]; // select 3rd cell
        oCell.focus(); // focus on the Input field
        break;
    }
}

答案 1 :(得分:0)

您可以尝试通过其ID获取视图,然后使用focus()函数将焦点设置为它。

例如,

var oInput = new sap.m.Input({id: "inputID"})
.addEventDelegate({
    onAfterRendering: function(){
        oInput.focus();
    }
});

或者如果您的输入有id,请说“input1”,那么您可以这样做

this.getView().byId("input1").focus();

编辑: 假设输入是您想要ID的元素,那么这样做很简单,

<Column width="6rem">
    <m:Label text="{i18n>Field2}" />
    <template>
        <m:Input
            value="{items>Field2}"
            id="input1" />
    </template>
</Column>