Reset filter parameters no working using SApUI5 - sapui5

After applying that filter, it adds to the request
&$filter=contains(Status, eq 'active')&$skip=0&$top=100
What I need is to be able to remove that filter
I tried to remove it with the Filter model
var oFilterModel = this.getView ().getModel("filters");
oFilterModel.setProperty ("/", {});
which if you reset the other filters of the type
aFilters.push (new Filter ("Name", FilterOperator.Contains, sName));

The problem is, that you try to manipulate the model. The filtering happens in the binding of the model. Therefore, you need to change the binding of the aggregation.
As shown here:
var oList = this.getView().byId("invoiceList");
var oBinding = oList.getBinding("items");
oBinding.filter([]);

Related

How to modify the available filter operators of a smart table

I have a smart table that shows data from odata service. all properties of the entity type are Edm.String.
now i can set a filter for each column of the resulting table with a lot of filter operators.
My goal is to filter the list of available filter operators depending on the selected column.
e.g.
selected colum 'A' then allow only 'equal to'.
Is that somehow possible? I would like to solve it in front end code.
I didn't find anything like that in ui5 docu...
you need to use equals FilterOperator
here is a link for FilterOperator and another example how to use filter in grid table https://sapui5.hana.ondemand.com/
Here is a quick example of setting more than one filter each with different Filter Operator
filterGlobally : function(oEvent) {
var sQuery = oEvent.getParameter("query");
this._oGlobalFilter = null;
if (sQuery) {
this._oGlobalFilter = new Filter([
new Filter("columA", FilterOperator.EQ, sQuery),
new Filter("columB", FilterOperator.Contains, sQuery)
], false);
}
var oFilter = null;
if (this._oGlobalFilter) {
oFilter = new Filter([this._oGlobalFilter], true);
}
this.byId("idTable").getBinding().filter(oFilter, "Application");

Filtering SmartTable that consists of multiple entity sets

I have a sap/ui/comp/smarttable/SmartTable which receives data of one EntitySet (MAINSet). The table has 5 columns. I added three extra columns manually where I put data from another EntitySet (DetailSet) when a specific button is pressed. I do that manually by iterating throw the table and setting the properties like this:
table.getModel().setProperty(sPath + "/EXAMPLE", EXAMPLE);
Filtering works fine for all the properties of the MAINSet. But filtering properties which I retrieve from the DETAILSet does not work with the following logic:
var oBinding = this.getView().byId("table0").getBinding("items");
var aFilter = [];
var sQuery = oEvent.getParameter("query");
if (sQuery) {
aFilter.push(new Filter("EXAMPLE", FilterOperator.Contains , sQuery));
}
oBinding.filter(aFilter);
Is there any way I can filter the SmartTable for the data received from the DETAILSet?

SapUi5 Table Multiple Filter

I'm developing a sap ui5 application using sap.ui.table.Table.
I need to apply a filter based on multiple strings. For example, if the user input is an array like:
["Stack", "Overflow"]
I need:
Filter all table fields by "Stack";
Filter the result of point 1 by "Overflow";
the result will be all rows that have "Stack" and "Overflow", no matter the field.
Does anyone have a solution?
As per the sap.ui.model.Filter documentation, you can create a filter either based on a filter info object, or from an array of previously created filters. This allows us to do the following:
Create a filter for the first value (eg "Stack")
Create a filter for the second value (eg "Overflow")
Create a filter which contains both of these values, and use it to filter the table.
Let's have a look at some code.
// We will only display rows where ProductName contains
// "Stack" AND CustomerName equals "Overflow"
var oFilterForProductName,
oFilterForCustomerName,
aArrayWhichContainsBothPreviousFilters = [],
oFilterToSetOnTheTable;
var sValueToFilterTheProductNameOn = "Stack",
sValueToFilterTheCustomerNameOn = "Overflow";
var sKeyForProductNameInTheTableModel = "ProductName",
sKeyForCustomerNameInTheTableModel = "CustomerName";
var oTableToFilter = this.byId("myTableId");
// Step 1: create two filters
oFilterForProductName = new sap.ui.model.Filter(
sKeyForProductNameInTheTableModel,
sap.ui.model.FilterOperator.Contains,
sValueToFilterTheProductNameOn);
oFilterForCustomerName = new sap.ui.model.Filter(
sKeyForCustomerNameInTheTableModel,
sap.ui.model.FilterOperator.EQ,
sValueToFilterTheCustomerNameOn);
// Step 2: add these two filters to an array
aArrayWhichContainsBothPreviousFilters.push(oFilterForProductName);
aArrayWhichContainsBothPreviousFilters.push(oFilterForCustomerName);
// Step 3: create a filter based on the array of filters
oFilterToSetOnTheTable = new sap.ui.model.Filter({
filters: aArrayWhichContainsBothPreviousFilters,
and: true
});
oTableToFilter.getBinding("items").filter(oFilterToSetOnTheTable , sap.ui.model.FilterType.Application);
Hope this helps. Let me know if you have any questions.
Chris
Please pass that array in for loop and pass filters like,
var tableId = this.byId("oTable");
for(var i=0;i < array.length ; i++)
{
oTable.getBinding().filter(new sap.ui.model.Filter("", sap.ui.model.FilterOperator.Contains, array[0]));
}
it may be helpful for you.

How to store the result data of an OData query to a JSON model

I have a filtering on an odata query. Is there a way to store the data of the result to another model (JSON). I need the search filter to search the items displayed on the list and not to search for the whole odata model.
updateProductsList : function(){
var filters = [];
filters.push(new sap.ui.model.Filter("SalesOrganization", sap.ui.model.FilterOperator.EQ, this.oSalesOrganization));
filters.push(new sap.ui.model.Filter("DistributionChannel", sap.ui.model.FilterOperator.EQ, this.DistributionChannel));
filters.push(new sap.ui.model.Filter("ProductID", sap.ui.model.FilterOperator.Contains, this.sFilterPattern));
filters.push(new sap.ui.model.Filter("CustomerNo", sap.ui.model.FilterOperator.EQ, this.oCustomerID));
this.setDefaultSelection = true;
this.getList().bindItems("/Products", new sap.ui.xmlfragment("cus.sd.salesorder.create.view.ProductListItemTemplate",this), null,filters);
console.log("getPRODList0 " + this.getList().bindItems("/Products", new sap.ui.xmlfragment("cus.sd.salesorder.create.view.ProductListItemTemplate",this), null,filters));
var sTitle = this.getView().byId("SOC_MasterListHeaderTitle");
sTitle.setText(this.oApplicationFacade.getResourceBundle().getText("PRODUCTS_CUST", [this.CustName]));
this.registerMasterListBind(this.getList());
console.log("getPRODList " + this.getList().getBinding("items").sPath);
console.log("getPRODList2 " + this.getList().getBindingContext());
console.log("getPRODList3 " + this.getList().getModel());
},
There are several ways to accomplish this. Probably the easiest way is to attach RequestCompleted function to your model that takes a copy of the model's content. You can attach a RequestCompleted function to your model using the Model.attachRequestCompleted function.
While writing the RequestCompleted handler, you could use the oEvents.getParameters() to check the context of the reponse to check whether this request is illegible for your copy-operation. Once you've check, you could just read the model using Model.getProperty("/Products") and copy the data into a JSON model.
Just a quick note: if you copy entries from your OData model to your JSON model, you may be copying references instead of copies. Be aware of this, and clone these entries if necessary.

Programmatically updating fields in Mongo and Meteor

I have a collection that I'd like to update. The field is given programmatically, so I'd like to do something like this:
var update_string = 'coordinates.lat';
var update = function(value, id, update_string) {
Collection.update({_id:id}, {$set:{update_string:value}})
}
That however does not work and just sets "update_string" to have value {{value}} in the object with _id {{id}} in the Collection. I also tried doing var update_string = "'coordinates.lat'"; to no avail.
How do I accomplish this? Thanks.
You need to set the key in your update $set parameter correctly:
var update = function(value, id, update_string) {
var update_query = {};
update_query[update_string] = value
Collection.update({_id:id}, {$set:update_query})
}
Basically without the modification above, If you used {update_string:value} you would be setting the value of update_string, not coordinates.lat.