locked
Sending group change events to the IListNotificationHandler (or not) RRS feed

  • Question

  • I'm currently in the process of implementing another custom grouped IListDataSource that is tailored to our internal data model. The main difference to the models used in the documentation and samples is, that in our app, one record may exist in multiple groups, i.e. correspond to multiple IItem. Now I wonder if I and what kind of notifications I need to send to any IListNotificationHandlers that are registered on the group data source.

    Will it be ok to just send notifications regarding the itemDataSource and the ListView will know by itself that the corresponding groups have changed? Since it already knows the start index (firstItemIndexHint) and end-index (firstItemIndexHint+groupSize) of each group, I would think that inserting new items at the correct index or removing items could be done without any explicit information about group change.

    A special case occurs when a newly inserted item starts a new group: do I first insert the item and then the group? Or the other way around? Is beginEdits() on both data sources mandatory in that case? My guess is that I'll have to update the internal data model for both data sources before notifying anyone, to avoid a catch 22 situation between the group and item data source status.

    The broader goal behind this is to avoid calling invalidateAll in favor of more specific avents and to otherwise prevent a complete re-drawing/flickering of a list when items are added, removed or changed. Especially during operations like import which will continuously add new elements, a complete refresh/flickering of the list makes the application seem very ugly and renders it unusable. Also, having move animations for element repositioning would be very nice to have.

    All the best
    Marcus

    Friday, July 27, 2012 12:22 PM

All replies

  • Update: during debugging, I came across the synchronizeGroups function in ui.js:16411 which suggests that one would have to update the groups first but I'm not sure if that's the case.

    Currently my ListView correctly shows the grouped items from my custom itemDataSource and groupDataSource but doesn't update correctly although there are 'changed' events for the groups and 'inserted' events for the items that are sent to the IListDataNotificationHandlers so I still must be missing something...

    Monday, July 30, 2012 4:23 PM
  • Hi,

    ListView’s grouping feature does not stand by the model where one item belongs to multiple groups. Please choose a “main” group which is bound to the ListView. If you run the samples related to ListView, you will find when you add a new item to a specific group, UI will automatically be reflected. If it doesn’t work in your application, I would like to suggest to try to compare your code with the samples. If you want to manually deliver change notification, please check http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2012/04/26/windows-8-metro-style-bits-of-binding.aspx for a sample.

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework

    Tuesday, July 31, 2012 12:53 PM
    Moderator
  • Hello Ming Xu,

    thank you for your reply. To solve the problem with one item being in multiple groups, we have implemented a special query which will fetch seperate multiple entries for each item that would appear in multiple groups by composing the group key and the item id into the item key which is used in the list.

    Displaying items works fine using this approach but the problem is when an element is updated and changes groups. Could you specify which sample you are refering to regarding adding new items to a group? What I currently do is

    - send beginEdits() to both item and group data source
    - move the item in the itemdatasource and send moved() notifications to the IListDataNotificationHandlers
    - decrease the size of the group it was previously in and send a changed() notification
    - increase the size of the new group and send a changed() notification
    - [both resize events will change the firstItemIndexHint of the other groups without sending a change notification for them, maybe that is what I need to do?]
    - send endEdits() to both item and group data source

    But for some reason yet unknown to me, this totally messes up the group rendering, so I think I'm still missing something. All the ListView samples that I saw which used grouping had static groups that were created using createGrouped or something like that.

    All the best
    Marcus

    Tuesday, July 31, 2012 3:54 PM
  • Hi,

    I have a similar problem.

    I have a grouped listview with custom datasources for items and groups. The data from items, changes in time and I tried to call IListDataNotificationHandler.changed in the custom adapter for items. The renderer function gets called, to display the new info but, a beginRefresh from VirtualizedDataSource is invoked(somewhere in the call stack I've seen invalidateAll) and gets stuck in a infinite loop, which calls continuously  itemsFromKey() from the custom IListDataAdapter of groups.

    Regards,

    Lucian

    Tuesday, September 18, 2012 3:25 PM