Skip to Content
avatar image
Former Member

how to bind json model to sap ui5 table

Hi Tech Guru's,

I have below code.

xml view

<tb:Table

id="attachmentsTable"

noDataText="No Attachments"

rows ="{/attModel}"

visibleRowCount = "10"

selectionMode = "None"

enableSelectAll="false"

>

<tb:columns>

<tb:Column width="12em">

<Label text="File Name" maxLines="0"/>

<tb:template>

<Text text="{FileName}" />

</tb:template>

</tb:Column>

<tb:Column hAlign="Right">

<Label text="Size" maxLines="0"/>

<tb:template>

<Text text="{FileSize}" />

</tb:template>

</tb:Column>

<tb:Column hAlign="Center" demandPopin="true">

<Label text="" maxLines="0"/>

<tb:template>

<Buttonicon="sap-icon://delete"iclass="rounded"press="onIssueUpdateClick"/>

</tb:template>

</tb:Column>

</tb:columns>

</tb:Table>

In controller file

var data = {

"FileName": fileName,

"FileSize": fileSize

};

attModel.setData(data);

this.getView().setModel(attModel);

viewObject.byId("attachmentsTable").bindRows("/attModel");

with this code, rows are not getting displayed in table, is there any problem in my coding?

As we have multiple model, tried put alias for the model as below, but that also not helpful.

this.getView().setModel(attModel,"MyModel");

viewObject.byId("attachmentsTable").bindRows("/MyModel");

Please help me in populating rows to UI5 table.

Thanks,

Sudhakar.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Feb 21, 2017 at 07:15 AM

    Hi,

    first remove rows property from table definition:

    rows ="{/attModel}"

    and your data should be as below:

    var data = [{ //data should enclosed with [ ]
        "FileName": "fileName", //keep values in side " "
        "FileSize": "fileSize"
    }];

    binding code is as below:

    var attModel = new sap.ui.model.json.JSONModel()
    attModel.setData(data);
    this.getView().setModel(attModel);
    this.getView().byId("attachmentsTable").bindRows("/");

    this will work!

    Thanks,

    Akhilesh

    Add comment
    10|10000 characters needed characters exceeded