on 02-06-2017 2:39 PM
Hi,
I have a list and object list item defined in XML View. I need to bind this list to oModel Entity Set at runtime , say after the click of Submit button.
I have two buttons and I need to call a different service on the click of each item and the respective results should be bind to this list.
On the click of one button, I am able to bind it to the list but I am not getting how to bind it when I click the other button as I will get a new entity set and I want to bind the result to the same view.
View Controller Code:
<List busyIndicatorDelay="{masterView>/delay}" growing="true" growingScrollToLoad="true" growingThreshold="10" id="list" items="{ path: '/StageCollection', sorter: { path: 'ObjectID', descending: true } }" mode="{= ${device>/system/phone} ? 'None' : 'SingleSelectMaster'}" noDataText="{masterView>/noDataText}" selectionChange="onSelectionChange" updateFinished="onUpdateFinished">
<items>
<ObjectListItem number="{StagingErrorCount}" numberUnit="Errors" numberState="Error" press="onSelectionChange" title="{ObjectID}" type="{= ${device>/system/phone} ? 'Active' : 'Inactive'}">
<attributes>
<ObjectAttribute active="false" text="{ObjectItemID}" /> </attributes> </ObjectListItem> </items>
</List>
Controller Code:
this._oScheduledDateFilter = new sap.ui.model.Filter("ScheduledDate", sap.ui.model.FilterOperator.EQ, this._oScheduledDate); oFilters.push(this._oScheduledDateFilter);
this._oObjectFilter = new sap.ui.model.Filter("ObjectType", sap.ui.model.FilterOperator.EQ, this._oObjectType);
oFilters.push(this._oObjectFilter);
var binding = oList.getBinding("items");
binding.filter(oFilters);
Hi Suresh,
Yes, this is possible with the code.
to connect to ECC model you can use the below code(assuming model name as 'ECCModel')
//Prepare filters
this._oScheduledDateFilter = new sap.ui.model.Filter("ScheduledDate",
sap.ui.model.FilterOperator.EQ,
this._oScheduledDate);
oFilters.push(this._oScheduledDateFilter);
this._oObjectFilter = new sap.ui.model.Filter("ObjectType",
sap.ui.model.FilterOperator.EQ,
this._oObjectType);
oFilters.push(this._oObjectFilter);
//update binding to ECC model
oList.bindAggregation("items", {
path: 'ECCModel>/StageCollection2',
template: new ObjectListItem({
number: "{myModel>StagingErrorCount}"
}),
filters: oFilters, //Filters
sorter: [] //pass sorter
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you want to bind a different service based on the button click then use generic method bindAggregation or use UI control specific binding method(in your case UI control is sap.m.List so the method will be bindItems() )
When you use bindAggregation it resets previous aggregation on UI control
I prefer using generic method, below is the sample code you can use
/**
for this example i'm assuming you have two paths 'StageCollection1' and 'StageCollection2' in named model 'myModel'.
On button click 1 you can bind 'StageCollection1' and on button click 2 you can bind 'StageCollection2'
**/
/**
(this refers to controller instance, if you are using this code in button event handler then this refers to button instance and the model cannot be accessed)
**/
var oModel = this.getComponentInstance().getModel(<name of your model>); //get model reference in manifest.json
var oList = this.getView().byId("list");
//list has an aggregation called 'items', set binding for this aggregation with path StageCollection2
oList.bindAggregation("items", {
path: 'myModel>/StageCollection2',
template: new ObjectListItem({
number: "{myModel>StagingErrorCount}"
}),
filters: [], //pass any required filters
sorter: [] //pass sorter
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Srikanth,
I have two models - one is from CRM and the other one is from ECC. These two models are declared in component.js file.
I have different entity sets say StageCollection1 and StageCollection2.
When I click a link in a tile, it should call the CRM service and fetch the results to show it in a split app and now when I click another link in a tile, it should call the ECC service to show the data in a split app view.
Previously we have only one service which is CRM and the controller code looks like below
this._oScheduledDateFilter = new sap.ui.model.Filter("ScheduledDate", sap.ui.model.FilterOperator.EQ, this._oScheduledDate); oFilters.push(this._oScheduledDateFilter);
this._oObjectFilter = new sap.ui.model.Filter("ObjectType", sap.ui.model.FilterOperator.EQ, this._oObjectType);
oFilters.push(this._oObjectFilter);
var binding = oList.getBinding("items");
binding.filter(oFilters);
Now I want to use the same when an action is performed for ECC. Is this achievable using the same logic?
Regards
V. Suresh Kumar
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.