fetch certain amount of records and show in table

1.9k views Asked by At

how to fetch records from database.I have 500 records i the database i want to fetch 200 records initlally and after user press more than i want to fetch another 200 records...I have done like below but am getting only 200 records if i use top=200.. if am not using top=200..then getting all records..

var url = "/sap/opu/odata/sap/ZODATA_CRUD_OPR_SRV/";
//Service Url
var oModel1 = new sap.ui.model.odata.ODataModel(url);
var oUrlParams = "$top=" + '200' + "&$skip=" +'0' ;

oModel1.read("/EmpDetails1Set", null,oUrlParams,true, function(oData){ //read method
oODataJSONModel.setData(oData); 
that.getView().setModel(oODataJSONModel,"emp");     
},
function(error) {

});

<Table id="table" width="auto"  growingScrollToLoad="false" growingThreshold="100" items="{emp>/results}" growing="true"> 

<columns>
    <Column id="nameColumn">
        <Text text="" id="nameColnTitle"/>
    </Column>
    <Column id="namolumn">
        <Text text="" id="nameCumnTitle"/>
    </Column>       
</columns>
    <items>
    <ColumnListItem type="Navigation"   press="onPress">
    <cells>
    <Text id="ob"   text="{emp>Name}"/> 
    <Text       text="{emp>Address}"/>  
    </cells>
    </ColumnListItem>
    </items>
    </Table>
1

There are 1 answers

1
Sunil B N On

Setting items="{/EmpDetails1Set}" is important by which it will call OData collection. I hope you have set /sap/opu/odata/sap/ZODATA_CRUD_OPR_SRV/ as your OData Service url of the application. By this method you don't need to set model data from controller to the view.

<?xml version="1.0" encoding="UTF-8"?>
<Table id="table" width="auto" growingScrollToLoad="false" growingThreshold="100" items="{/EmpDetails1Set}" growing="true">
   <columns>
      <Column id="nameColumn">
         <Text text="" id="nameColnTitle" />
      </Column>
      <Column id="namolumn">
         <Text text="" id="nameCumnTitle" />
      </Column>
   </columns>
   <items>
      <ColumnListItem type="Navigation" press="onPress">
         <cells>
            <Text id="ob" text="{Name}" />
            <Text text="{Address}" />
         </cells>
      </ColumnListItem>
   <items>
</Table>