/scripts/ahub.form.attachments.js
0

How to refresh list in sapui5

Apr 13, 2017 at 12:15 PM

1.4k

avatar image

I've a list which is initialized when application starts. I'm performing crud operation. when i'm deleting any item, or adding any item, It doesn't refreshed.

var listRules=that.getView().byId("lstAutomationRules");
listRules.getModel().refresh();

I use above approach to refresh my list. but it doesn't work. the code of list back-end is as below.

<List id="lstAutomationRules" itemPress="onListItemPress" showUnread="true" items="{/d/results}">
	<infoToolbar>
		<Toolbar visible="false" id="idInfoToolbar">
			<Label id="idFilterLabel"/>
		</Toolbar>
	</infoToolbar>
	<items>
		<StandardListItem title="{name}" type="Active" description="{description}" custom:to="{id}"/>
	</items>
</List>
//prepare url for fetching records.....
var url = sap.samhengi.util.replaceDoubleCurleyBrackets(that.conf.fetchAutomationRules);
$.ajax({
url: url,
method: "GET",
dataType: "json",
headers: {
	"Accept": "application/ld-frame+json"
}
}).done(function(data) {
var oModel = new sap.ui.model.json.JSONModel(data);
//binding model... 
that.getView().setModel(oModel);
}).fail(function(error) {
reject();
});
});
refreshlist.png (34.9 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Akhilesh Upadhyay Apr 13, 2017 at 12:57 PM
0

try below code once:

oList.getModel().updateBindings(true)

Show 4 Share
10 |10000 characters needed characters left characters exceeded

doesn't work

0

why you are not using read operation to read the data ? why ajax?

as per my understanding, if you will perform model.read operation and do model.refresh(true), then your model and respective binding should get refreshed with updated data.

And in your current scenario, if you are removing data from model only, then automatically list would be refreshed with updated data (since json model is twoway binding),

if you are deleting data from backend and you wants to refresh list wont work, you need to trigger your backend call again to get he updated data and do what you are doing with ajax.

0

any example for "model.read operation" ?

0
0
Dennis Seah
Apr 16, 2017 at 09:45 PM
0

HI Nafees

I believe that it is due to caching. I may be wrong. try this (cache: false)

$.ajax({
url: url,
method: "GET",
dataType: "json",
cache: false,
headers: {
	"Accept": "application/ld-frame+json"
}

Thanks

-D

Share
10 |10000 characters needed characters left characters exceeded
Skip to Content