Search code examples
sapui5

Table sap.ui.table shows the same record


I try to use this table.

But I can do what I want in the UI table are shown a lot of the same records. In the DB table I do have only one record. In my case I'm using a JSONModel and an Ajax Call through the DB. The result of this call looks fine within the chrome console. There is only one record as I would expect. My first idea was that it must have something to do with the key. But there is a key. I really don't have a clue what I'm doing wrong.

result: {
  "data": [{
    "WirkstoffID": 1,
    "PatientID": "12",
    "PZN": 12101,
    "Wirkstoff": "stoff",
    "Wirkstaerke": "blabla"
  }]
}

View

 <t:Table class="sapUiContentPadding" height="496px" width="1092px" id="idTable" selectionMode="MultiToggle" rows="{modelWirkstoff>/0/}">
  <t:columns>

    <t:Column id="idPatientID" width="142px">
      <Text class="size12" text="PatientID" />
      <t:template>
        <Text text="{modelWirkstoff>/0/PatientID}" wrapping="false" />
      </t:template>
    </t:Column> 

Any ideas?


Solution

  • You bind the table rows against the first entry instead of the array. The runtime does not complain abouts this and adds a column for every property it can determine. Below is a fixed example:

    <t:Table rows="{modelWirkstoff>/result/data}">
        <t:columns>
            <t:Column id="idPatientID" width="142px">
                <Text class="size12" text="PatientID"/>
                <t:template>
                    <Text text="{modelWirkstoff>PatientID}" wrapping="false"/>
                </t:template>
            </t:Column>
        </t:columns>
    </t:Table>