Skip to Content
author's profile photo Former Member
Former Member

sap.m.Table refresh items

Hi All,

I have created a simple app which has a view with a SearchField and Table. The search field also has liveChange feature and when the function is called, I call my query to backend system using oModel.read().

In the SearchField, the user can type either a material number or material description and as a result of liveChange, data is displayed in the table below the SearchField

When I delete the typed in text, the search results adjust accordingly, and when the searchfield is empty, no data is shown:

Problem: The problem begins when I start typing in the search field again, it appears that the table has lost its items cells structure.

The above view was created in XML.

I have created the same view in JS and it works fine.

Any suggestions? Please ask for more information and I will provide it as required.

Thanks.

Initial Screen.jpg (15.1 kB)
livechange.png (9.9 kB)
nodata.png (6.6 kB)
retype.png (3.8 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 29, 2016 at 01:54 AM

    Resolved using the following code:

    onInit: function() {
         var oTab = this.getView().byId("idTblMat");
         oTab.setModel(oJsonModelS);
         oTab.bindItems("/results", this.getView().byId("idColListItem") , null, null);
    },
    
    


    liveChange

    onSearch : function (oControlEvent) {
    
         var sPlant = this.getView().byId("idSelPlant");
         var oTab = this.getView().byId("idTblMat");
         
         var sQuery = oControlEvent.getParameter("newValue");
         if (sQuery) {
    
              oModelS.read("/MaterialSet?$filter=Werks eq '"
              +sPlant.getSelectedKey()+
              "' and Maktg eq '"
              +sQuery+
              "' and Matnr eq '"
              +sQuery+
              "' ",
              null,null,false,function(oData,repsonse){
              oJsonModelS.setData(oData);
              oTab.bindItems("/results", sap.ui.getCore().byId("idColListItem") , null, null);
         });
    
         } else {
              oJsonModelS.setData();
         }
    },
    
    
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 20, 2016 at 03:18 AM

    Hi Aabhas,

    If possible, can you share the code for table filter?

    Regards,

    Sai Vellanki.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Sai Vellanki

      Hi Sai,

      I guess you are doing it the right way and I am using a different approch.

      Here's what I am doing:

      Controller:

      onInit: function() {
           var oTab = this.getView().byId("idTblMat");
           oTab.bindItems("/results", this.getView().byId("idColListItem") , null, null);
        },
      
      

      //liveChange

      onSearch : function (oControlEvent) {
      
      
        var sPlant = this.getView().byId("idSelPlant");
        var oTab = this.getView().byId("idTblMat");
      
        var sQuery = oControlEvent.getParameter("newValue");
        if (sQuery) {
            oModelS.read("/MaterialSet?$filter=Werks eq '"
             +sPlant.getSelectedKey()+
             "' and Maktg eq '"
             +sQuery+
             "' and Matnr eq '"
             +sQuery+
             "' ",
             null,null,false,function(oData,repsonse){
                       oJsonModelS.setData(oData);
                       sap.ui.getCore().setModel(oJsonModelS);
                  });
      
             } else {
                  oJsonModelS.setData();
             }
      
        },
      
      
      

      View:

      ...

      <SearchField id="idSearchMat" showSearchButton="false"
        emphasized="true" enableSuggestions="true"
        placeholder="Please search for a material number or material description here..."
        search="onSearch" liveChange="onChange">
      </SearchField>
      
      
      <Table id="idTblMat" itemPress="onItemPress">
        <columns>
             <Column width="24em">
                  <Text text="Material" />
             </Column>
             <Column width="48em">
                  <Text text="Description" />
             </Column>
             <Column>
                  <Text text="Storage Bin" />
             </Column>
             <Column hAlign="Right">
                  <Text text="Available" />
             </Column>
        </columns>
        <items path="/results">
             <ColumnListItem type="Navigation" id="idColListItem">
                  <cells>
                       <Label text="{Matnr}"></Label>
                       <Label text="{Maktx}" design="Bold"></Label>
                      <Label text="{Lgpbe}"></Label>
                      <ObjectNumber number="{Labst}" unit="{Meins}" />
                  </cells>
             </ColumnListItem>
        </items>
      </Table>
      
      

      ...

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.