Skip to Content
avatar image
Former Member

Getting error in filtering a data in table while consuming data from odata services.

Hi,

I am Getting error in filtering a data in table while consuming data from odata services and the table lies in value help control.I am able to get data in table through odata service but when i enter the company code value in search field and press go button data in table is not updated.Kindly look into the problem.


find the attachment of the output screen.

Controller

onInit: function() {

var oDataModel = new sap.ui.model.odata.ODataModel("service url",  true, "username",  "password");

sap.ui.getCore().setModel(oDataModel,"oDataModel1");


this.theTokenInput= this.getView().byId("multiInput1");

  this.aKeys= ["CompanyCode","CompanyCodeName"];

var token1= new sap.m.Token({key: "001", text: "Construction"});

  this.aTokens= [token1];

  this.theTokenInput.setTokens(this.aTokens);


},


onValueHelpRequest: function() {

  var that= this;

  var oValueHelpDialog = new sap.ui.comp.valuehelpdialog.ValueHelpDialog({

  basicSearchText: this.theTokenInput.getValue(),

  title: "Company",

  supportMultiselect: true,

  supportRangesOnly: false,

  key: this.aKeys[0],

  descriptionKey: this.aKeys[1],

  ok: function(oControlEvent) {

  that.aTokens = oControlEvent.getParameter("tokens");

  that.theTokenInput.setTokens(that.aTokens);

  oValueHelpDialog.close();

  },

  cancel: function() {

  sap.m.MessageToast.show("Cancel pressed!");

  oValueHelpDialog.close();

  },

  afterClose: function() {

  oValueHelpDialog.destroy();

  }

  });

  var oColModel = new sap.ui.model.json.JSONModel();

  oColModel.setData({

  cols: [

        {label: "Company Code", template: "CompanyCode"},

        {label: "CompanyCodeName", template: "CompanyCodeName"}

        ]

  });

  oValueHelpDialog.getTable().setModel(oColModel, "columns");

  oValueHelpDialog.getTable().setModel(sap.ui.getCore().getModel("oDataModel1"));

  oValueHelpDialog.getTable().bindRows("/CompanyCodeValuehelp");

  oValueHelpDialog.setRangeKeyFields([{label: "Company Code", key: "Company Code"}, {label : "CompanyCodeName", key:"CompanyCodeName"}]);

  oValueHelpDialog.setTokens(this.aTokens);

  var oFilterBar = new sap.ui.comp.filterbar.FilterBar({

  advancedMode:  true,

  filterBarExpanded: true,

  searchEnabled:true,

  filterGroupItems: [new sap.ui.comp.filterbar.FilterGroupItem({ groupTitle: "foo", groupName: "gn1", name: "n1", label: "Company Code", control: new sap.m.Input()}),

                    new sap.ui.comp.filterbar.FilterGroupItem({ groupTitle: "foo", groupName: "gn1", name: "n2", label: "CompanyCodeName", control: new sap.m.Input()})],

                    search: function(oEvt) {

        var aFilters = [];

      

        var sQuery = oEvt.getSource().getValue();

        if (sQuery && sQuery.length > 0) {

        var filter = new sap.ui.model.Filter("CompanyCode", sap.ui.model.FilterOperator.Contains, sQuery);

        aFilters.push(filter);

        }

        var oColModel = new sap.ui.model.json.JSONModel();

        oColModel.setData({

        cols: [

              {label: "Company Code", template: "CompanyCode"},

           {label: "CompanyCodeName", template: "CompanyCodeName"}

              ]

        });

        oValueHelpDialog.getTable().setModel(oColModel, "columns");

      

        oValueHelpDialog.getTable().setModel(sap.ui.getCore().getModel("oDataModel1"));

      

        oValueHelpDialog.getTable().bindRows("/CompanyCodeValuehelp");

   

        oValueHelpDialog.getTable().filter(aFilters,"Application");

      

                    }

  });


Error


I am getting error in console


Uncaught TypeError: oEvt.getSource(...).getValue is not a function



Regards,

Monika



error1.PNG (31.0 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Oct 29, 2015 at 05:01 AM

    Hi Monika,

    In your search event, instead of oEvt.getSource().getValue(); try like this -

    var sQuery = oEvt.getParameter("query");
    
    
    

    And also have a break point in your search event and check in console the value of oEvt. See if you have something in that event.


    Regards,

    Sai Vellanki.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Sai Vellanki

      In multiinput i used valueHelpRequest and Value help view is in controller itsellf .I already posted  controller part .check my above post  

      Regards,

      Monika

  • Oct 29, 2015 at 10:09 AM

    Hi Monika,

    I guess you have to define conditions for search. However check this sample where I written logic for search box, now it filters with company code. Provide any company code in search box and click on GO button, value help dialog table will be filtered.

    Sample: Plunker


    Also, can you elaborate your requirement -


    1. Which value should be provided on search field?

    2. Do you want advanced search also available?


    Regards,

    Sai Vellanki.

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Monika,

      If the data volume is huge then you should always use Odata Model for binding because it is server side model which brings only limited records(conceptually called as lazy loading) and does not cause much load on the network. 

      In your case you can pass filters to the OData call as below -

      oFilterProcessType = new sap.ui.model.Filter("<FILTER_FIELD_NAME>",sap.ui.model.FilterOperator.EQ,"<FILTER_FIELD_VALUE>");

                    aSorters.push(new sap.ui.model.Sorter("<SORT_FIELD_NAME>", true));

                    oModel.read("/<NAME_OF_COLLECTION>",{filters: [oFilterProcessType],

                           sorters: aSorters, success: function (OData,oResponse){

                                 if (OData.results.length > 0)

                                 {

      // OData call was successful and data was also returned

                                 }

                                 else

                                 {

      // OData call was successful but no data was returned.

                                 }

                           },

                           error : function(){

                                 alert("Read failed");}

      BR.

  • Oct 29, 2015 at 01:16 PM

    Hi Monika,

    One more thing, scrap the old logic used for search.

    There are two types of search in filter bar control. One normal search that is search box. For this you have to create sap.m.SearchField control and you should say new sap.ui.comp.filterbar.FilterBar.setBasicSearch(new sap.m.Search());

    In search you can provide either CompanyCode/Currency Code /Company Name value and you should press keyboard enter button (or) the search icon. (NOT the GO button)


    There is advanced search as well, here you can provide only Company code in company code input and other fields with respect to their values etc.. and you should press 'GO' button to filter the table. (NOT the keyboard ENTER button)


    Check this Sample, you will understand: Plunker

    Screenshot: Image


    Regards,

    Sai Vellanki.

    Add comment
    10|10000 characters needed characters exceeded

    • Better solution to this problem is convert odata model to json format and

      set the data to a json model defined within

      valueHelpPress function.

      1. var oRowsModel = new sap.ui.model.json.JSONModel();
      2. oRowsModel.setData(this.aItems);
      3. oValueHelpDialog.getTable().setModel(oRowsModel);

      Check the bind row's path it differ's when calling odata service and binding json data.