Skip to Content
0

sap.m XML table no data available issue

Dec 18, 2017 at 10:33 AM

45

avatar image
Former Member

Hi Team,

I am a naive developer in SAP UI5 and I am facing difficulties while retrieving data from a odata model and binding it back to the sap.m table in a XML view.

Below is the piece of code I have done and all the time I don't get results in the TABLE UI and it shows No data always.

<Label id="orderLbl" text="Order:" textAlign="center" required="true" labelFor="orderTxt" design="Bold"/>
 <Input id="orderTxt" placeholder="Enter Order#" />
 <Button id="orderSerach" text="Search" press="onSearch" icon="sap-icon://search" />



 <Table id="internalOrderDetails" fixedLayout="false" 
items="{path:'tabModel>items'}" type="responsive" 
showNoData="true">
 <columns>
 <Column width="12em" >
 <Text id="pt1" text="Order" />
 </Column>
 <Column width="12em">
 <Text id="pt2" text="Order Type" />
 </Column>
 <Column width="12em">
 <Text id="pt3" text="Entered By" />
 </Column>
 <Column width="12em">
 <Text id="pt4" text="Created On" />
 </Column>
 <Column width="12em" demandPopin="true">
 <Text id="pt5" text="Description" />
 </Column>
 <Column width="12em">
 <Text id="pt6" text="Company Code" />
 </Column>
 <Column width="12em">
 <Text id="pt7" text="Plant" />
 </Column>

 </columns>
 <items>
 <ColumnListItem>
 <cells>
 <Text text="{path:'tabModel>AUFNR'}"/>
 <Text text="{path:'tabModel>AUART'}"/>
 <Text text="{path:'tabModel>ERNAM'}"/>
 <Text text="{path:'tabModel>ERDAT'}"/>
 <Text text="{path:'tabModel>KTEXT'}"/>
 <Text text="{path:'tabModel>BUKRS'}"/>
 <Text text="{path:'tabModel>WERKS'}"/>
 </cells>
 </ColumnListItem>
 </items> 
 </Table>



Controller code.

onSearch: function(oEvent){

var oView = this.getView();
 var param1 = oView.byId("orderTxt");
 var param2 = param1.getValue();
 
 var oTable = oView.byId("internalOrderDetails");
 
 
 var serviceURL2 = "/sap/opu/odata/sap/XXXXXXXX_SRV"; 
 var dataModel = new sap.ui.model.odata.ODataModel(serviceURL2,false);
 dataModel.read("/Order_detailSet(AUFNR='"+param2+"')", 
 {
 method: "GET",
 success: function(dataModel) {
console.log(dataModel);
 },
 error: function() {

 }
 });

 
 oTable.setModel(dataModel,"tabModel"); 

 }

WHile I debug and put the result on console, I get the odata results in the console and its only issue with the binding i believe

Regards,
Madhav

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Irfan Gokak Dec 18, 2017 at 02:46 PM
0

Hi,

Do as following.

// In odata success call
success: function(dataModel) {
// Create JSON Model for your data var oJson = new sap.ui.model.json.JSONModel({'items':dataModel.results}); this.getView().setModel(oJson,"tabModel") }, // In view <Table id="internalOrderDetails" fixedLayout="false" items="{path:'tabModel>/items'}" type="responsive" showNoData="true">
<columns> <Column width="12em" > <Text id="pt1" text="Order" /> </Column> <Column width="12em"> <Text id="pt2" text="Order Type" /> </Column> <Column width="12em"> <Text id="pt3" text="Entered By" /> </Column> <Column width="12em"> <Text id="pt4" text="Created On" /> </Column> <Column width="12em" demandPopin="true"> <Text id="pt5" text="Description" /> </Column> <Column width="12em"> <Text id="pt6" text="Company Code" /> </Column> <Column width="12em"> <Text id="pt7" text="Plant" /> </Column> </columns> <items> <ColumnListItem> <cells> <Text text="{path:'tabModel>AUFNR'}"/> <Text text="{path:'tabModel>AUART'}"/> <Text text="{path:'tabModel>ERNAM'}"/> <Text text="{path:'tabModel>ERDAT'}"/> <Text text="{path:'tabModel>KTEXT'}"/> <Text text="{path:'tabModel>BUKRS'}"/> <Text text="{path:'tabModel>WERKS'}"/> </cells> </ColumnListItem> </items> </Table>

Try this. It will work. If not then share the the response screenshot.

Share
10 |10000 characters needed characters left characters exceeded