cancel
Showing results for 
Search instead for 
Did you mean: 

Handling filter in case of formatter applied to the field and multifield handling concept

former_member338801
Participant
0 Kudos
702

Hi Experts,

I am facing one issue in the filter code that gives wrong search results. The issue is happening when UI value is manipulated using formatter function. I have used json file to load the data and test. If you search in the status field with value Keep or Remove but in the odata/json values are Y or N or " ". It should give relevant list of items but it's not working. You may get whole code in the zip file. Let me know in case you need any further details. Please suggest how to handle this scenario where I am getting different data from the oData/Jason but on the UI manipulating to achieve different result but how to search it.

You can get the zip file for the same in the below url. You can download the file and import in your web ide to test.

ztableLiveChange.zip

Git hub url : https://github.com/rkmishra2703/RK-

XML code :
<SearchField search="onSearch" width="40%"/>

<Text id="idStatus" text="{parts :['MAN_APPROVE','TEAMLEAD_APPR'],formatter: '.formatter.availableColor'}" modelContextChange="updateColor">

Controller code :
onSearch: function(oEvent) {
   var that=this;
  var sQuery = oEvent.getSource().getValue();
   //var sQuery = oEvent.getParameter("newValue");
   var oList = that.getView().byId("idTable");
   var oBinding = oList.getBinding("items");
   
   if (sQuery) {
    var aFilter = [];
    aFilter.push(new Filter("MAN_USER_ID", FilterOperator.Contains, sQuery));
    aFilter.push(new Filter("USER_ID", FilterOperator.Contains, sQuery));
    aFilter.push(new Filter("EMP_FIRST_NAME", FilterOperator.Contains, sQuery));
    aFilter.push(new Filter("T_CODE", FilterOperator.Contains, sQuery));
    aFilter.push(new Filter("T_CODE_DSCRIPTN", FilterOperator.Contains, sQuery));
    aFilter.push(new Filter("TEAMLEAD_FUNAREA", FilterOperator.Contains, sQuery));
    aFilter.push(new Filter("MAN_APPROVE", FilterOperator.EQ, sQuery));
    aFilter.push(new Filter("TEAMLEAD_APPR", FilterOperator.EQ, sQuery));
                aFilter.push(new Filter("TEAMLEAD_APPR_ID", FilterOperator.Contains, sQuery));
               
    oBinding.filter(new Filter({
     filters: aFilter,
     and: false
    }));
   
   } else {
    
    oBinding.filter([]);
   }
  }

formatter function :
availableColor: function (available, available1) {
    if (available === "" && available1 === "Y") {
     return "Keep";
    } else if (available === "Y" && available1 === "Y") {
     return "Keep";
    } else if (available === "N" && available1 === "Y") {
     return "Keep";
    } else if (available === "Y" && available1 === "") {
     return "Keep";
    } else if (available === "" && available1 === "") {
     return "";
    } else if (available === "" && available1 === "N") {
     return "Remove";
    } else if (available === "N" && available1 === "N") {
     return "Remove";
    } else if (available === "Y" && available1 === "N") {
     return "Remove";
    } else {
     return "Remove";
    }
   }

View Entire Topic
maheshpalavalli
Active Contributor

Hi ram.mishra

Formatter is only to format the data in the UI and that also only the visible items in the table. It will not update the model.

So what you can do for this is to

1. Before binding the data, update the data manually in the model and bind it back to the table. Else if it is odata direct binding to the table, ask odata/backend team to provide an additional field for that.

2. Not the best way and bit complex in your scenario: on search, check if the value is "keep" and do the reverse derivation of what availableColor is doing and fill the filters with those values.

-Mahesh

former_member338801
Participant
0 Kudos

Thanks Mahesh

Can you please elaborate a bit as mentioned in the point no. 1.

1. Before binding the data, update the data manually in the model and bind it back to the table. Else if it is odata direct binding to the table, ask ui team to provide an additional field for that.

maheshpalavalli
Active Contributor
0 Kudos

Hi ram.mishra,

Welcome,

I mean, read the data manually using odata read function and instead of using the formatter, manually loop the data and create a new property and update the status text there and show it in the UI.

-Mahesh

former_member338801
Participant
0 Kudos

Thanks for reply but to achieve this requirement. I don't think it is possible to achieve search in manual way as well.There should be model parameter that should be fixed to set the data in it. Here I have to put condition based upon two model parameters.

maheshpalavalli
Active Contributor
0 Kudos

ram.mishra What I am saying is that , once you receive the data, create the property as below and use that property in your view to show the status and filter on.

success: function(data){
/........

data.forEach(function(mObj){
   mObj.status = " Do your status derivation logic here..
}, this);

now your data will have "Status field/property, use that in your table to show status without formater and you can filter on the same filed.

/.......
}.bind(this)
former_member338801
Participant
0 Kudos

Thanks Mahesh

I would like to add this url that helped to solve the issue. It might help if someone need it.

https://stackoverflow.com/questions/38922998/add-property-to-an-array-of-objects