Filtering SmartTable that consists of multiple entity sets - sapui5

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?

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");

Smart Table expand to 2 entity sets?

onBeforeRebind: function(oEvent)
{
var mBindingParams =oEvent.getParameter("bindingParams");
mBindingParams.parameters["expand"] = "Supplier";
}
How do I expand to 2 entity sets, suppose i have Supplier and Product List Items?
You can put a comma between entity sets as follows:
mBindingParams.parameters["expand"] = "Supplier,SecondEntitySet,ThirdEntitySet";

Reset filter parameters no working using 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([]);

Get Selected Value from Drop-Down Inside sap.ui.table.Table

I have created a table with a drop-down control (sap.m.ComboBox). I am adding rows dynamically using JSONModel. Here is the logic to bind my table:
My Table bind logic.
Now, I am trying to get values from the table:
var oTable = this.getView().byId("mytable");
var data = oTable.getModel();
var len = oTable._iBindingLength; // Get total Line Items in table
for (var i = 0; i < len; i++) {
var _val1 = data.oData[i].item1;
var _val2 = data.oData[i].item2;
// my value logic here
}
But this is bringing all the values instead of just selected value from my drop-down control.
If you want to get selected key from the ComboBox (drop-down), bind the appropriate model data to its property selectedKey. Once the user selects something, the selected key will be stored in the model thanks to the two-way data binding.
<m:ComboBox width="100%"
selectedKey="{foo/selectedKey}"
items="{
path: 'foo/items',
templateShareable: false
}"
>
<core:Item key="{key}" text="{text}"/>
</m:ComboBox>
I've updated my example from your previous question: https://plnkr.co/edit/8YvXxk?p=preview
The model data is automatically updated when the user selects something from the drop-down:

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.