locked
Tips on having a ListView bound to storage files, but with grouping capabilities RRS feed

  • Question

  • The official documentation mentions that StorageDataSource doesn't support grouping. 

    My goal is to display library items in a nice gallery, but there can be many of them. I would really like to be able to group items. Right now I'm thinking about calling getFilesAsync() on the StorageDataSource, and build a WinJS.Binding.List manually out of it. As I lose the binding with the file system, I imagine there's a better way.

    What is the suggested way of doing this? Does it involve creating a custom data source? I'd appreciate if someone could explain the high-level parts in making this possible. 

    Wednesday, July 25, 2012 11:36 PM

Answers

  • Hi,

    Your solution works fine in general. It is a good idea to separate view from the actual data (model). Today you may only need to display a list of local files. But what if a new requirement comes, for example, display files from SkyDrive? By introducing a middle layer, you can abstract the actual data.

    As for monitoring file system change, actually WinRT does not expose this feature, even if you directly bind the data to view. From my experience, there is a StorageFolderQueryResult.ContentsChanged event that may partially meet your requirement.

    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

    Monday, July 30, 2012 3:22 PM
    Moderator

All replies

  • What I'm thinking so far:

    - Build a file query targetting the folder/library I'm interested in
    - Build list of files with getFilesAsync() 
    - Generate a list of objects that correspond to the groups of files 
    - Feed the list of files to a custom data source, bound to itemDataSource of the ListView
    - Feed the list of group objects to another custom data source, bound to groupDataSource of the ListView

    Both custom data sources would follow the scenario 4 of the "HTML ListView working with data sources" sample.

    But then, how can I monitor file system changes and what would be an efficient way of updating my data sources? 

    Any comments welcome.

    Thursday, July 26, 2012 5:04 AM
  • Hi,

    Your solution works fine in general. It is a good idea to separate view from the actual data (model). Today you may only need to display a list of local files. But what if a new requirement comes, for example, display files from SkyDrive? By introducing a middle layer, you can abstract the actual data.

    As for monitoring file system change, actually WinRT does not expose this feature, even if you directly bind the data to view. From my experience, there is a StorageFolderQueryResult.ContentsChanged event that may partially meet your requirement.

    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

    Monday, July 30, 2012 3:22 PM
    Moderator