cancel
Showing results for 
Search instead for 
Did you mean: 

Table Databinding

RenaldWittwer
Contributor
0 Kudos

Hi,

I have a problem with the databinding for a sap.m Table. The following example works fine as expected. The Model is set as root model, I used the JSON file from the Fiori example:


<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"

  controllerName="table.MainView" xmlns:html="http://www.w3.org/1999/xhtml">

<Page title="Title">

  <content>

      <Table

        headerText="Test Table"

        items="{/SalesOrderCollection}">

        <columns>

          <Column>

            <header><Label text="Sales Order Id" /></header>

          </Column>

          <Column>

            <header><Label text="Status" /></header>

          </Column>

          <Column>

            <header><Label text="Created by" /></header>

          </Column>

        </columns>   

        <ColumnListItem

            type="Navigation"

            press="handleLineItemPress" >

            <cells>

              <ObjectIdentifier

                  title="{SoId}" />

              <Text

                  text="{Status}" />

              <Text

                  text="{CreatedByBp}" />

            </cells>    

        </ColumnListItem>

      </Table>

  </content>

</Page>

</core:View>




This is how I set the Model

  onInit: function() {

  // Using a local model for offline development

  var oModel = new sap.ui.model.json.JSONModel("mock.json");

  this.getView().setModel(oModel);

  },

And here the begin of the Model:

{

  "SalesOrderCollection": [

  {

  "SoId": "300000097",

  "ApprovalStatus": "",

  "Status": "Initial",

  "ConfirmationStatus": "",

  "BillingStatus": "Initial",

  "OrderingStatus": "",

  "OrderingStatusDesc": "Initial",

  "LifecycleStatus": "P",

  "LifecycleStatusDesc": "",

  "GrossAmount": "13224.47",

  "BuyerName": "11113.00",

  "TaxAmount": "2111.47",

And now the problem. I want to set the model not as root, so I changed the following line (line 4)


onInit: function() {

  // Using a local model for offline development

  var oModel = new sap.ui.model.json.JSONModel("mock.json");

  this.getView().setModel(oModel, "Order");

  },



In the XML View I changed the line 7

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"

  controllerName="table.MainView" xmlns:html="http://www.w3.org/1999/xhtml">

<Page title="Title">

  <content>

      <Table

        headerText="Test Table"

        items="{Order>/SalesOrderCollection}">

        <columns>

          <Column>

            <header><Label text="Sales Order Id" /></header>

          </Column>

          <Column>

            <header><Label text="Status" /></header>

          </Column>

          <Column>

            <header><Label text="Created by" /></header>

          </Column>

        </columns>   

        <ColumnListItem

            type="Navigation"

            press="handleLineItemPress" >

            <cells>

              <ObjectIdentifier

                  title="{SoId}" />

              <Text

                  text="{Status}" />

              <Text

                  text="{CreatedByBp}" />

            </cells>    

        </ColumnListItem>

      </Table>

  </content>

</Page>

</core:View>




The result is an empty table, the rows are shown but the columns are empty. This means for me, that the table can be found, but the data in the table not.

What is my mistake?

Thanks for help and sorry for so much code.

Best regards

Renald

PS Why do I have perfekt syntax highlighting in the edit mode but not if I show this threat?

Accepted Solutions (1)

Accepted Solutions (1)

SandipAgarwalla
Active Contributor
0 Kudos

the property need to be added wih the model name

<ObjectIdentifier

                  title="{moelName>/SoId}" />

              <Text

                 

RenaldWittwer
Contributor
0 Kudos

Hi Sandip,

thanks for your answer. I just gave it a try. Unfortunately it does not work, I still get empty rows.

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"

  controllerName="table.MainView" xmlns:html="http://www.w3.org/1999/xhtml">

<Page title="Title">

  <content>

      <Table

        headerText="Test Table"

        items="{Order>/SalesOrderCollection}">

        <columns>

          <Column>

            <header><Label text="Sales Order Id" /></header>

          </Column>

          <Column>

            <header><Label text="Status" /></header>

          </Column>

          <Column>

            <header><Label text="Created by" /></header>

          </Column>

        </columns>  

        <ColumnListItem

            type="Navigation"

            press="handleLineItemPress" >

            <cells>

              <ObjectIdentifier

                  title="{Order>/SoId}" />

              <Text

                  text="{Order>/Status}" />

              <Text

                  text="{Order>/CreatedByBp}" />

            </cells>   

        </ColumnListItem>

      </Table>

  </content>

</Page>

</core:View>

SandipAgarwalla
Active Contributor
0 Kudos

Can you try removing the '/' in the property bindings

    title="{Order>SoId}" />   


       text="{Order>Status}" />

RenaldWittwer
Contributor
0 Kudos

Hello Sandip,

thats it, now it works. Thanks a lot!

Best regards

Renald

Answers (0)