Reputation: 174
I have a listview using the data-input property to provide a filter. After I dynamically change the listview, I call listview refresh. Even though there is still text in the filter input, the filter is not applied. You can see the problem in this fiddle:
Here is the html that sets it up:
<div id="aPage" data-role="page">
<div data-role="content">
<form>
<input data-type="search" type="text" id="aFilter" />
</form>
<ul id="aList" data-role="listview" data-filter="true" data-input="#aFilter">
<li>aaa</li><li>bbb</li>
</ul>
<a data-role='button' href='#bpage'>test</a>
</div>
</div>
<div data-role='page' id='bpage'>
<div data-role="header">
<a data-rel="back" data-role="button">Back</a>
</div>
</div>
Here is the dynamic load and refresh that runs when you return to the page:
$(document).on('pagebeforeshow', '#aPage', function() {
$('#aList li').remove();
$('#aList').append($("<li>").append('aaa'));
$('#aList').append($("<li>").append('bbc'));
$("#aList").listview('refresh');
});
Filter, then click the test button, then go back and you'll see that the filter doesn't work. I've tried triggering a change function on the filter, but that doesn't work either. Any ideas how I can get the listview to filter again based on the input?
Upvotes: 1
Views: 1226
Reputation: 174
Omar's last comment above worked. I didn't realize there was a separate widget that I should call refresh on.
$("#aList").filterable("refresh");
That keeps the existing filter and refreshes the list to reflect the results of the filter.
Thanks.
Upvotes: 1