Skip to Content
0

Issue displaying odata in SAPUI5 Smart Table

Feb 09, 2017 at 11:22 AM

1.1k

avatar image

Hi Guys,

I am trying to use the Smart Table control instead of sap.m.table in my project. On following the reference in SAPUI5 Explored I used the Filter and Table code.

The below code was used in my controller instead of loading data from the mock server.

I am able to get the sorter and filters but my Smart Table shows "No Data".

The errors I get on performing the filter operation are

1. Error: resource smarttableSmartTable/Component-changes.json could not be loaded from ./Component-changes.json. Check for 'file not found' or parse errors. Reason: Not Found -

2. 'getChanges' failed: -

Please provide suggestions as to where I could have gone wrong.

Thanks,

Srinivasan

jQuery.sap.require("sap.ui.core.util.MockServer");
var oModel;
var oMockServer = new sap.ui.core.util.MockServer({
rootUri: "/sap/opu/odata/SAP/ZCFS_CUSTOMER_LIST_SRV/"
});
this._oMockServer = oMockServer;
oMockServer.simulate("localService/ZCFS_CUSTOMER_LIST_SRV/metadata.xml", "localServiceZCFS_CUSTOMER_LIST_SRV");
oMockServer.start();
oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/SAP/ZCFS_CUSTOMER_LIST_SRV/", true);
oModel.setCountSupported(false);
var oView = this.getView();
oView.setModel(oModel);
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Radek Chudziak Feb 10, 2017 at 04:16 PM
1

Add the following parameter to your smart table:

initiallyVisibleFields="Kunnr1,Name1"
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Radek,

I added the property to my smart table. This is the response I get inside the table

No results found. Adjust your search and filter settings.
0
Veeraraghavan Narasimhan
Feb 09, 2017 at 03:47 PM
0

Hello Srinivasan,

The above error you get can be ignored . This is a general that call that UI5 framework makes to check for certain files . Absence of this will not hurt the application. What i am interested in seeing is the Smart table binding. Can you share that. I am pretty sure that is where the issue is.

Thanks and Regards,

Veera

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Veera,

Thank you for your reply. I have shared the Smart Table binding below for our reference.

<smartFilterBar:SmartFilterBar id="smartFilterBar" entityType="ZCFS_Cust" persistencyKey="SmartFilter_Explored" basicSearchFieldName="Kunnr" enableBasicSearch="true">
<smartFilterBar:controlConfiguration>
<smartFilterBar:ControlConfiguration key="Kunnr">
<smartFilterBar:defaultFilterValues>
<smartFilterBar:SelectOption low="301676">
</smartFilterBar:SelectOption>
</smartFilterBar:defaultFilterValues>
</smartFilterBar:ControlConfiguration>
<smartFilterBar:ControlConfiguration key="Name1">
<smartFilterBar:defaultFilterValues>
<smartFilterBar:SelectOption low="Robs Solutions">
</smartFilterBar:SelectOption>
</smartFilterBar:defaultFilterValues>
</smartFilterBar:ControlConfiguration>
</smartFilterBar:controlConfiguration> 
</smartFilterBar:SmartFilterBar>
<smartTable:SmartTable id="LineItemsSmartTable" entitySet="ZCFS_CustSet" smartFilterId="smartFilterBar" tableType="Table" useExportToExcel="true" useVariantManagement="true" useTablePersonalisation="true" header="Line Items"showRowCount="true" persistencyKey="SmartTableAnalytical_Explored" enableAutoBinding="true" demandPopin="true" app:useSmartField="true">
</smartTable:SmartTable>

Regards,

Srinivasan

0

Hello Srinivasan,

I think since no fields are visible in your smart name , there is no binding being triggered.

Couple of ways to quickly check this.

1. Click on the settings button select any column and click ok, this should trigger the data.

2. Add some fields in the attribute InitiallyVisibleFields ="Field1,Field2"(couple of fields in the entity).

If the above works you have 2 solutions

Do as #2 mentioned above or use Lineitem annotations in backend to fix the issue.

Thanks and Regards,

Veera

0
Veeraraghavan Narasimhan

Hi Veera,

I tried both the steps as you have suggested. I am getting an error as attached below. Is the error occurring because the odata call did not happen properly?

Regards,

Srinivasan

smt-error.png (44.2 kB)
0
Toney Benoy Feb 10, 2017 at 08:38 AM
0

Hi Srinivasan,

In order to use mock server the data must be available with in the the app itself .

Please refer this link before perusing other options : https://sapui5.hana.ondemand.com/#docs/guide/50897decc9504b2a875fb41d89fd254a.html

Hope this solution helps .

Regards,

Toney C Benoy

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Toney,

You are exactly correct but instead of the mock server url I have given the path for my metadata.xml that is set in the app. Hope I haven't followed the wrong approach.

Regards,

Srinivasan

0

Hi Srini,

Metadata is data about data.. means i holds the properties

Using this (/sap/opu/odata/SAP/ZCFS_CUSTOMER_LIST_SRV/) you are pointing to SAP system right using mock data don't work like that . i think you have to maintain a metadata file as well as a data that contains the value to show it in the smart table .

I hope this information helps

Regards,

Toney C Benoy

0

Hi Toney,

With your help I understand that using Service URL for mock data would not help but in the manifest file I have defined the Data Sources and default model for the app. After this step I got a metadata file under the localService folder.

Now suppose I give the entity set to be bound in the Smart Table where would I specify the path for the app to locate the metadata file. I am struck with this path.

Thanks,

Srinivasan

0
Basavaraja Goudar Feb 15, 2017 at 05:08 PM
0

Hi Srenivasan,

There are 2 ways to get the default columns to smart table.

First it looks for metadata for below annotation, if this not defined you have option to provide via smart table property as Radek mentioned. initiallyVisibleFields="Kunnr1,Name1"

<Annotation Term=”com.sap.vocabularies.UI.v1.LineItem”>

Then table is formed is rendered with columns with either of the above options.

Once table is rendered the binding is triggered with the entityset you have provided and this will be a request to server with url as below

/sap/opu/odata/SAP/ZCFS_CUSTOMER_LIST_SRV/ZCFS_CustSet?

see if this returns data!!

If not you might have some default filters to pass to fetch data which can be handled in onBeforeBinding event of smart table.

onBeforeRebindTable: function(oEvent) {
var mBindingParams = oEvent.getParameter("bindingParams");
var aFilter = [];
if (<if filter has value>) {
aFilter.push(new sap.ui.model.Filter("<fieldname>", sap.ui.model.FilterOperator.EQ, "<filtervalue>"));
mBindingParams.filters = aFilter;
}
},

you can also click on go button to get the data if service url above works to get data, you can fire the request from browser to see what is the response.

Regards,

BG

Share
10 |10000 characters needed characters left characters exceeded
Basavaraja Goudar Feb 15, 2017 at 05:12 PM
0

One more thing to note, variant management will not work from web development (WebIDE or Eclipse) you have to deploy the code to ABAP repository then create a tile for your app in the launch pad, then your app will show-up in the launchpad where you can use variant management to save table changes and filter changes.

Good Luck!!

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi BG,

Thank you for sharing the info. It was quite useful knowing about variant management and the usage of Smart Table. I will try your suggestions and get back for further queries if any.

Regards,

Srinivasan

0

Hi BG,

The first way you suggested worked. Now I am able to get the data inside the Table and I can display/hide fields.

But the SmartFilter control does not work. Though the buttons are visible, it is graded out. Please provide suggestions regarding the same.

Thanks,

Srinivasan

0