How to filtering information on the second page based on data on the first page in SAPUI5? [duplicate] - sapui5

This question already has answers here:
XXX is a table without a header line and therefore has no component called "EBELN"
(2 answers)
Closed 2 years ago.
I have a table. The first field of this table contains ID data.
When I click the marked button, I go to the second page. And this page has a few tables below as well.
Like this...
I get ID data in the background while adding data to the second table.
All of the tables have different IDs. When I go to the second page, I want the fields with the same ID to appear.
For example, when I click on the line with ID 000001, ENG with ID 1 should appear on the second page.
I applied such a filter for this but it didn't work:
onPress: function (oEvent) {
// The source is the list item that got pressed
this._showObject(oEvent.getSource());
var sFilterData = this.getView().getModel("kisiselBilgiler").getData();//first table json model id
var aFilter = [];
aFilter.push(new Filter("perId", FilterOperator.EQ, sFilterData.Id));
var oBinding = this.getView().byId("lisanTable").getBinding("items"); //second table id
oBinding.filter(aFilter);
},
My kisiselBilgiler Json Model in Worklist.controller.js:
onInit: function () {
// <<<<<<<<< KİŞİSEL BAŞLANGIÇ
var kisiselData = {
Id: "",
İsim: "",
dTarih: yeni Tarih (),
Posta: "",
isAdrc: "",
Hakkinda: "",
Lisans: "",
Uyruk: ""
};
var oModel = new JSONModel (kisiselData);
this.getView (). setModel (oModel, "kisiselBilgiler");
}, ...
The table I want to bind in Object.view.xml:
<Table id="lisanTable" width="auto" items="{ path: '/lisanSet', sorter: { path: 'perId', descending: false }, filters: [{path: 'perId'}] }"
noDataText="{worklistView>/tableNoDataText}" busyIndicatorDelay="{worklistView>/tableBusyDelay}" growing="true" growingScrollToLoad="true"
updateFinished=".onUpdateFinished">
<columns>
<Column>
<Text text="{i18n>perLisan}"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{perLisan}"/>
</cells>
</ColumnListItem>
</items>
</Table>
My error:
How can I do it?
NOTE: Github link of the project: https://github.com/shrgrl/CVApp

That FM is expecting a single field, not a table column. You need to loop at lt_mbbez and pass a single record value into that FM at a time.
loop at lt_mbbez assigning field-symbol(<mbbez>).
CALL FUNCTION 'C14Z_MESSAGES_SHOW_AS_POPUP'
EXPORTING
i_msgid = 'ZSG_INFO_MSG'
i_msgty = 'I'
i_msgno = '000'
i_msgv1 = <mbbez>-mbbez
i_lineno = 1.
endloop.
The error message is funky because once upon a time you could declare a table with an implicit header line, and it would have the same name as the table (well you still can in some contexts, but you shouldn’t).

Related

Saving values in custom smart filter field

In this smart filter example: https://sapui5.hana.ondemand.com/#/sample/sap.ui.comp.sample.smartfilterbar.example2/preview
.. a custom field is used. It's defined like this:
<smartFilterBar:ControlConfiguration
key="MyOwnFilterField" index="1" label="Custom Filter Field"
groupId="_BASIC" width="300px" mandatory="mandatory"
visibleInAdvancedArea="true">
<smartFilterBar:customControl>
<m:Select id="foo" customData:hasValue="true">
<core:Item key="1" text="ONE"/>
<core:Item key="2" text="TWO"/>
<core:Item key="3" text="THREE"/>
</m:Select>
</smartFilterBar:customControl>
</smartFilterBar:ControlConfiguration>
The values and selected keys of all fields are saved when the variant is saved, except for the values in the custom field.
I also want to store the values in the custom field, in the example it's a select. Is there a way to do that?
Since I'm saving the selected keys and values of my custom controls in a JSON model, saving and restoring them with the LREP payload turned out to be reasonably straight forward. Setting a _CUSTOM key on the filter data populates a JSON model set on the filter bar itself called fi1t3rM0d31.
So for this field:
<smartFilterBar:ControlConfiguration
key="OrderTypeId"
index="0"
label="{i18n>orders.enquiry.ordertype}"
groupId="_BASIC"
visibleInAdvancedArea="true"
controlType="input">
<smartFilterBar:customControl>
<MultiComboBox
customData:hasValue="true"
selectedKeys='{filters>/filters/multi/OrderTypeId}'
items="{
templateShareable: 'true', path: '/HelpValues',
filters: [{path:'FieldName', operator:'EQ', value1: 'VBAK-AUART'}]
}">
<core:ListItem key="{Key}" text="{Value}"/>
</MultiComboBox>
</smartFilterBar:customControl>
</smartFilterBar:ControlConfiguration>
I can use these events on the Filter bar:
/**
* This event on the smart filter bar triggers before a variant is saved
* #param {sap.ui.base.Event} oEvent
*/
beforeVariantSave: function(oEvent) {
oEvent.getSource().setFilterData({_CUSTOM:this.getModel('filters').getProperty('/filters')});
},
/**
* This event on the smart filter bar triggers after a variant is loaded
* #param {sap.ui.base.Event} oEvent
*/
afterVariantLoad: function(oEvent) {
var custom = oEvent.getSource().getFilterData()._CUSTOM;
this.getModel('filters').setProperty('/filters', custom);
},
... which in turns allows me to generate filters like this in the beforeRebindTable event on the smart table.
//multi keys
Object.keys(data.multi || {}).forEach(k => {
var f = [];
data.multi[k].forEach(v => {
if (v) f.push(new Filter(k, FilterOperator.EQ, v));
});
if (f.length > 0) {
this.aFilters.push(new Filter(f));
}
});

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:

Applying a sap.ui.model.Filter on two sap.m.Table columns combined

Two columns firstName and lastName.
How can the filter method of a binding be used so that a query from a search field where a person enters John Doe keep records where the concatenation of firstName + " " + lastName matches?
Note: I'm doing this on a client side operation mode so no backend filtering solutions please.
The correct solution is using Custom Filter as pointed out by: #Andrii.
So, we can create a custom filter which will run for every row in the table and based on the returned boolean value from
the custom filter a row is rendererd on screen. Filter API: Filter
So, below is the running code:
handleSearch: function(e) {
var sQuery = e.getParameter('query'); // Fecth search term
var oCustomFilter = new sap.ui.model.Filter({
path:"", // this refers to binding path of each row.
test: function(oNode) {
var oValue = oNode.fname + " " +oNode.lname;
if (oValue.indexOf(sQuery) !== -1) {
return true; // row will be rendererd
} else {
return false; // row will not be rendererd
}
}
});
var oBinding = this._table.getBinding('items');
oBinding.filter(oCustomFilter);
}
TABLE:
<Table
id='idTable'
items= "{/}"
>
<columns>
<Column
headerText='FName'
/>
<Column
headerText='LName'
/>
</columns>
<items>
<ColumnListItem>
<cells>
<Text
text='{fname}'
/>
<Text
text='{lname}'
/>
</cells>
</ColumnListItem>
</items>
</Table>
Let me know if you need any additional infomation. :)

SAPUI5 - filter table by value calculated with formatter

I want to filter table by value calculated with formatter. I calculate certain value with formatter and display it in table.
<ObjectStatus
text="{
path: 'values/',
formatter: '.formatter.calculate'}"/>
My question is if I can filter table by this calculated value and how? Do I need to add custom formating?
Filters are applied in controller:
let oFilter = new sap.ui.model.Filter(sPath, vOperator, vValue1);
aFilters.push(oFilter);
oBinding.filter(aFilters);
You can get the formatted value by accessing the control from the view and calling getText()
You'll need to assign an ID, first.
<ObjectStatus
id="objectStatus"
text="{
path: 'values/',
formatter: '.formatter.calculate'}"/>
Then in your controller:
var sFilterValue = this.getView().byId("objectStatus").getText();
var oFilter = new sap.ui.model.Filter(sPath, vOperator, sFilterValue);
oBinding.filter(oFilter);

How to get values from input in sap.ui.table.Table?

In sap.ui.table.Table I have input field in one column. It will get nearly 300 records of data from back-end and binded in other columns.
User manually enters in the input field. Further, when he clicks on submit button I have to take all values from all input as array. Please give suggestions.
You can do it using data binding of table, as invoking getRows() on Table control to access Input fields of each row would not help in this case;it only returns only currently visible rows and you have around 300 records to access.
Here is the solution:
Get all data from back-end in JSONModel.
Add one property say inputValue to each item in model's data by iterating over it.
Bind this model to table and use inputValue property in table's template to bind column containing Input fields.
As JSONModel supports two-way binding, all the values which user has entered in an Input fields are available in your model.
And, lastly iterate over model's data to get inputValue for each row.
Above steps in action:
Step 1 and 2:
setModelForTable: function() {
var oModel = sap.ui.model.json.JSONModel( < URLToLoadJSON > );
var length = oModel.getData().results.length;
for (var i = 0; i < length; i++) {
var path = "/results/" + i + "/inputValue";
oModel.setProperty(path, "");
}
}
Step 3:
Now, that you have model with inputValue property in all the items of data, set the model on table; which will show all the Input fields in columns empty initially and will update the corresponding model entry as user modifies it.
<t:Column>
<t:label>
<Text text="User Input" />
</t:label>
<t:template>
<Input value="{inputValue}" />
</t:template>
</t:Column>
Finally, get all entered values in array.
var length = oModel.getData().results.length;
var aInputvalues = []
for (var i = 0; i < length; i++) {
var path = "/results/" + i + "/inputValue";
aInputvalues.push(oModel.getProperty(path));
}
I had the case which is a bit similar and I did it in the following way. Will work if you really do not need records which are not changed.
have a variable to store [] of changed records
Attach change to input field
on change push changed record to a variable
var source = event.getSource();
source.getModel().getProperty(source.getBindingContext().getPath());
or the value of the input field.
event.getSource().getValue();
In case you have a record Id you can just push this ID and input value.
4. on submit iterate through an []