locked
Dynamic list.createFiltered() with grouping

    Question

  • Hi All,

    I have a WinJS.Binding.List which I'm applying both filtering and then grouping to. I've based the start of my data.js from the grid app VS template, so I have a basic revealing module pattern for my data.

    What I'd like to do is apply a 'createFiltered' to my datasource based on a parameter, so reapplying the 'itemDataSource' in that method. I'm working with the data by initially calling createFiltered and then calling createGrouped on the result.

    What I seem to have a problem with is exposing the result of createGrouped, in a way where it can be altered dynamically. 

    The template code exposes a var something = somit.createGrouped(); statement, but with this being a variable, it's only called once (when the script is loaded) and as a result doesn't update when I try to change the underlying data.

    I can make things switch dynamically by creating two grouped lists in my Data class like this:

    var listOne = data.createFiltered(//true condition);
    var listTwo = data.createFiltered(//false condition);
    var something = listOne.createGrouped();
    var somethingElse = listTwo.createGrouped();
        WinJS.Namespace.define("Data", {
    
            trueStuff: something,
            falseStuff: somethingElse
    });

    And then I can switch the dataSource between trueStuff and falseStuff in my button click handler.

    It feels like I should be able to pass a boolean to my 'Data' namespace in some way to avoid all the duplication here but I can't seem to get things to tie together properly.

    Is there any advice on the best way to go about this kind of thing?

    Many thanks,

    Doug


    • Edited by dougajmcdonald Monday, April 22, 2013 9:11 PM code formatting
    Monday, April 22, 2013 9:10 PM

Answers

  • Hi,

    When the page loads the list anyways rebinds the data. You have to call the logic to re create the data so that before binding it is re calculated.

    I guess you will have to have a function (in common place(say data.js):

    WinJS.Namespace.define("Data", {
    
            trueStuff: something,
            falseStuff: somethingElse,
            reloaddata : datareload
    
    });
    
    function datareload()
    {
     //logic to  get data for first list (listOne)
    
    //logic to  get data for secondlist (listTwo)
    
    
    //logic to  get grouped data for firstlist (something)
    
    //logic to  get grouped data for secondlist (somethingElse)
    }

    Then in the page ready event you can call this :

    ready: function (element, options) {
    Data.reloaddata(); // Call to re load the data
    
    // Do other stuff like binding etc.
    }

    - Girija

     

     


    Wednesday, April 24, 2013 10:18 PM

All replies

  • If you are changing data, you need to re run the whole logic for filtering and grouping again. The data.js is called once when the default loads.

    - Girija

    Tuesday, April 23, 2013 8:05 PM
  • Hi Girija,

    You're right, I may need to. I was planning to handle this logic separately. 

    Imagine this requirement as a 'show/hide archived' switch for example. The archived state of the items would only be changed via a separate explicit function which would in turn reload the data.

    Following on from you point however, how would you write your data functions for in order to re-run them each page load/function call? Simply reload all the data from the datasource and rebind to all the affected controls explicitly each time the view on the data changed?

    Cheers,

    Doug

    Wednesday, April 24, 2013 3:58 PM
  • Hi,

    When the page loads the list anyways rebinds the data. You have to call the logic to re create the data so that before binding it is re calculated.

    I guess you will have to have a function (in common place(say data.js):

    WinJS.Namespace.define("Data", {
    
            trueStuff: something,
            falseStuff: somethingElse,
            reloaddata : datareload
    
    });
    
    function datareload()
    {
     //logic to  get data for first list (listOne)
    
    //logic to  get data for secondlist (listTwo)
    
    
    //logic to  get grouped data for firstlist (something)
    
    //logic to  get grouped data for secondlist (somethingElse)
    }

    Then in the page ready event you can call this :

    ready: function (element, options) {
    Data.reloaddata(); // Call to re load the data
    
    // Do other stuff like binding etc.
    }

    - Girija

     

     


    Wednesday, April 24, 2013 10:18 PM