on 2020 Apr 22 7:35 PM
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.
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";
}
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
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
User | Count |
---|---|
71 | |
11 | |
10 | |
10 | |
10 | |
8 | |
7 | |
7 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.