简体   繁体   中英

Data not visible in table SAP UI5

Please find the controller and view code mentioned below:

I have created a table using eclipse in SAP UI5, but data is not visible. There is no error in console and in network tab all calls are showing fine as attached.

How to proceed?

Network Image

Console Image

Controller Code:

sap.ui
        .controller(
                "alp_report.alp",
                {

            /**
                * Called when a controller is instantiated and its View
                * controls (if available) are already created. Can be used
                     * to modify the View before it is displayed, to bind event
                     * handlers and do other one-time initialization.
                     * 
                     * @memberOf alp_report.alp
                     */
                    onInit : function() {
                        that = this;
                        // debugger;
                        var sUrl = "proxy/http/igwd01.sap.com:8000/sap/opu/odata/sap/ZMSI_POLICY_SRV";
                        var path = "/poldtlsSet";

                        // Instantiate Model
                        var oModel = new sap.ui.model.odata.v2.ODataModel(sUrl,
                                false);
                        this.getView("vw1").setModel(oModel);
                        debugger;
                        oModel.read(path, {
                            async : true,
                            success : function(oData) {
                                debugger;
                                that.byId("lblCount").setText(
                                        "Total Records(" + oData.results.length
                                                + ")");

                                var json = new sap.ui.model.json.JSONModel();
                                json.setData({
                                    'modelData' : oData.results
                                });

                                that.getView().byId("oTable").setModel(oModel,
                                        "json");
                            },
                            error : function(e) {
                                MessageToast.show("Failed");
                            }
                        });
                    },
                     

Please find the view code as below:

View Code:

<core:View id="vw1" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m" controllerName="alp_report.alp" xmlns:html="http://www.w3.org/1999/xhtml">
<Page title="ALP Report">
    <content>
        <Table id="oTable" items="{path:'/modelData'}">
            <headerToolbar>
                <Toolbar>
                    <Title level="H2" id="lblCount"></Title>
                    <SearchField id="searchField" width="auto"></SearchField>
                </Toolbar>
            </headerToolbar>
            <columns>
                <Column>
                    <Label design="Bold" text="Policy ID"></Label>
                </Column>
                <Column>
                    <Label design="Bold" text="Policy Number"></Label>
                </Column>
                <Column>
                    <Label design="Bold" text="Policy Begin Date"></Label>
                </Column>
                <Column>
                    <Label design="Bold" text="Journal No"></Label>
                </Column>
                <Column>
                    <Label design="Bold" text="Branch"></Label>
                </Column>
                <Column>
                    <Label design="Bold" text="Policy Status"></Label>
                </Column>
            </columns>
            <items>
                <ColumnListItem>
                    <cells>
                        <Text text="{SecpolId}"></Text>
                        <Text text="{PolicynrTt}"></Text>
                        <Text text="{PolbegDt}"></Text>
                        <Text text="{JournalnoId}"></Text>
                        <Text text="{ZzbranchCd}"></Text>
                        <Text text="{ZzPolicyStatusCd}"></Text>
                    </cells>
                </ColumnListItem>
            </items>
        </Table>
    </content>
</Page>

</core:View>

  1. As Jorg touched on, there are easier ways to do this, like directly bind to the entity set once you've created the oData model (You don't have to manually trigger oModel.read).

  2. In your current implementation,

     var json = new sap.ui.model.json.JSONModel(); json.setData({ 'modelData' : oData.results }); that.getView().byId("oTable").setModel(oModel,"json");

You've created a json model and then while setting it to the table, used the variable containing the OData model. Should be that.getView().byId("oTable").setModel(json,"json");

Since you're creating the model after the view gets rendered, you might also want to refresh the model bindings once json.refresh(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM