How Do You Filter and Sort Data in a CollectionView - maui

I have a CollectionView on a page that is displaying data from a List<> of items. I do sorting and filtering in a code behind on the page by changing the List with LINQ, and then setting the BindingContext of the view, like this:
MyView.BindingContext = FilteredData;
On IOS this works fine, every time, no problem. On Android, I can change the data a few times (it varies - normally three to five) and then the page doesn't display any data. In the debugger I can check and still see the ItemsSource has all of the items, but nothing is displayed. I then "switch" to my other view on the page, which is done by hiding one DataGrid row and showing another, then "switching" back. The data still isn't displayed, but after I do that I can run the code again that does the sorting and filtering and it starts working again - the data is displayed on the page. Not only that, but after I do that, it works every time from that point forward on Android.
I've spent hours trying every thing I can think of to try and find an event or property or anything that would indicate when this problem occurs so I can try and find a work around for it. I'm at a complete loss; wondering if there are suggestions for how to capture and/or fix this problem.

I did find a combination that worked to resolve this issue. I changed the page so that the CollectionView at issue is in the Grid row that has a non-zero (i.e. visible) height when the ContentPage loads. After doing that, the code works as expected. Previously, it was in a Grid.Row whose height was set to an absolute 0 when the page loaded, and then the height was changed to a non-zero value when a button was clicked.
FWIW, this is similar to other issues I've seen with MAUI on Android, where the visibility of certain controls as well as the order in which you modify them can interfere with rendering data binding results.

I solved sorting using a SortedList and made the list items inherit from IComparable, but I don't love the solution because a SortedList is not an ObservableCollection, and because implementing IComparable can be tricky and leaky.

Related

DatePicker and ListPicker display incorrectly

I am using a DatePicker along with a ListPicker in my Nativescript application. However neither of these elements display correctly. I've had to blank out some sensitive information from the screenshot, but the issue is visible in the DatePicker.
It seems that the values are offset, and I cannot find out what is causing this. Has anyone else come across this issue before? Or have a fix for it?
These elements are of utmost importance to my project.
This happens because the component is inside tag ScrollView. If I remove it, works. I have tried remove padding and margin of ScrollView and nothing.
The inner StackLayout is required for the ScrollView to work properly. If I have more than one element (such as an input form - which is the scenario in my application), only the last element is displayed without the StackLayout.

Auto-refresh a ListView within a ViewPager?

I'm having a bit of trouble approaching an auto-refresh design I want to implement.
Currently I have a TitlePageIndicator that sets its view pager with a PagerAdapter.
Each page in the view pager is a listview that is constructed based on a list of date strings.
In my instantiateItem() method, I call an AsyncTask to load data based on the date. This works well, and loads the way I want.
I recently changed all my listviews to PullToRefresh list views, in order to make sure a user could update the data on a date they wished to have the most up-to-date info on. (This also works the way I desire).
However now I want to somehow refresh a certain date in the view pager (Current date for instance) - every 60 seconds. So I'm not refreshing all the listivews in the viewpager, i'm just refreshing the one I want.
I started making a timer thread based on this :
Update TextView within custom ListView
But soon got very stumped and I'm not sure what to do next..
Can someone point me in the right direction?

Dynamic number of buttons on GWT UI

I have a MVP type application where I will have a view that contains one or more buttons. The number of buttons is not known till run time and may vary each time the page is rendered. What is the best way to approach this apart from a simple loop that will just display 1 - n number of buttons that are passed to the view?
My suggestion: Add all the buttons on creation and use CSS to hide or show them dynamically. I think this will yield less DOM manipulations and still works the same, also it might produce a simpler code. I currently do it that way using SmartGwt.

iPhone tableview pagination

First, please believe me when I say I did search for this answer first... a lot. I found many examples, but none performing similarly to what I need. Though I could have been searching using the wrong key words, I don't believe so.
Here is my issue:
I have a table view being populated by a query that is returning a huge amount of data. The data is for a list of restaurants, a price rating, and id. But there are so many restaurants in the database that it fills memory and crashes the app most time. (I am assuming this is what is going on, as the code works just fine if the query is limited, and has always worked on other pages I query things that don't have as much data returned.)
What I would like to do is make pagination for the application's table view for this page. I don't see how I could use the "Show More" method, or the auto load when scrolled to the bottom, simply because if you scroll down to the end of the list, you will still have the same issue: filling memory. Is there a way to do web-like pagination where (if they are not on the first page) they have a "Previous" cell at the top and (if not on the last page) a "Next" cell at the bottom? These would have to clear the cells out in the current view and drop the data so we're not just adding data which would cause the same issue, then do a new query to populate the cells.
Of course, I do not expect someone to sit here and write all that code for me. The main part I would need is just how to set up the cells for the next and previous cells. I should be able to figure the rest out after that, but I don't know how to go about clearing the data from the current table view.
Thanks for any help or suggestions.
I think you can do with a show more method or loading as you scroll, you say the problem is that you still load a bunch all the data and youll run out of memory, but you can avoid that... One option is, save to disk or just release data that isnt being shown on the table view, you can use indexPathsForVisibleRows method of UITableView to see which cells are visible, and with that info you should know which data you can safely release... You can do this either when you receive memory warnings, or maybe as cells are scrolled off the screen (up to you)...
Hope this helps
Daniel

How can I change a ViewController list (by changing predicate) without popping and pushing?

I have a ViewController whose view results from data from a fetch request with Predicate 1. I'd like to repeat the fetch request with a more restrictive Predicate 2 that will give a SUBSET of the data using Predicate 1.
Then I'd like to update (and possibly animate) that view on the iPhone screen by pressing a toggle button, so that the old and new views expand and collapse the rows. (I don't want to do this modally, as I'd like the user to see which rows came from the old rows.)
I'm thinking of something like the Phone application on the iPhone. Under the "Recents" tab, you'll see "All" and "Missed" buttons. When you press these buttons, it switches between showing all calls and just the missed ones by expanding/collapsing the rows. As far as I can tell, this is not a modal transition.
Can someone give me pointers as to how to do this?
If your view is a UITableView, you can use a combination of
-deleteRowsAtIndexPaths:withRowAnimation:
and
-deleteSections:withRowAnimation:
as well as the corresponding -insert methods, if applicable. You can batch multiple changes (so they animate at the same time) with -beginUpdates and -endUpdates.
I'm not aware of any way you'll be able to do this that doesn't involve iterating over one of the two sets and repeatedly calling -indexForObject on the other, though.
I found a way to expand/collapse rows by changing the heights of each cell, using tableView:heightForRowsAtIndexPath:indexPath:, as in:
http://www.alexandre-gomes.com/?p=482
Hope that's helpful to someone!