locked
Force grid view item to navigate to a specific page

    Question

  • I'm using a grid view application ... what I want to do is to when I invoke a specific item navigate to a specific page.

    here is the code when I invoke an item my problem is I can't get the index of an item .

            _itemInvoked: function (args) {
                var group = Data.groups.getAt(args.detail.itemIndex);
                var item  = Data.items.getAt(args.detail.itemIndex);
                element.querySelector("#multisizebaseitemtemplate");
    
                if (appView.value === appViewState.snapped) {
                    // If the page is snapped, the user invoked a group.
                    this.navigateToGroup(group.key);
                } else {
                    // If the page is not snapped, the user invoked an item.
                    if ( item.index == 1 ) {
                        nav.navigate("../../nextPage.html", { item: Data.getItemReference(item) });
    
    //                nav.navigate("../../nextPage.html");
                    }
                }
            }
    
        });

    Wednesday, January 23, 2013 10:10 PM

Answers

  • There is no groupIndex property.

    args.detail.itemIndex is an integer which gives you the index of the item based on the complete bound list. (Data.items).

    You should look carefully at the model to understand how it works. Look at the code below, and read my comments : 

          _itemInvoked: function (args) {
             if (appView.value === appViewState.snapped) {
                var group = Data.groups.getAt(args.detail.itemIndex);
                this.navigateToGroup(group.key);
             } else {
                // We retrieve the actual reference to the selected item
                var item = Data.items.getAt(args.detail.itemIndex);
                // In our model, each item has a group property, so you can retrieve it.
                var group = item.group;            
    
                nav.navigate("/pages/itemDetail/itemDetail.html", { item: Data.getItemReference(item) });
             }
          }

    Thee is no groupIndex property, but instead you have a key, that you can find with group.key.



    http://www.renauddumont.be

    • Marked as answer by Song Tian Tuesday, January 29, 2013 10:27 AM
    • Unmarked as answer by Ruezaki Tuesday, January 29, 2013 2:04 PM
    • Marked as answer by Ruezaki Tuesday, January 29, 2013 2:04 PM
    Sunday, January 27, 2013 10:05 AM

All replies

  • here is a figure explain what I mean

    http://www.flickr.com/photos/magedelgazzar/8409848728/in/photostream

    Wednesday, January 23, 2013 10:52 PM
  • Here is the default code that you can find in the groupedItem.js file when you create a new project based on the Grid App template :

            _itemInvoked: function (args) {
                if (appView.value === appViewState.snapped) {
                    // Si la page est alignée, l'utilisateur a appelé un groupe.
                    var group = Data.groups.getAt(args.detail.itemIndex);
                    this.navigateToGroup(group.key);
                } else {
                    // Si la page n'est pas alignée, l'utilisateur a appelé un élément.
                    var item = Data.items.getAt(args.detail.itemIndex);
                    nav.navigate("/pages/itemDetail/itemDetail.html", { item: Data.getItemReference(item) });
                }
            }


    To retrieve the index of the invoked item in the Grid, you have to use this property : 

    args.detail.itemIndex

    In your code, you call item.index.

    item is actually your model. Do you have an index property in your item object? 

    So maybe try this:

    if ( args.detail.itemIndex == 1 ) {
       nav.navigate("../../nextPage.html", { item: Data.getItemReference(item) });
    }

    http://www.renauddumont.be

    Thursday, January 24, 2013 8:21 AM
  • if ( args.detail.itemIndex == 1 ) { nav.navigate("../../nextPage.html", { item: Data.getItemReference(item) }); }

    ok that's works fine .. thank you. but if I need to get the group index also what should I do ?

    i tried args.detail.itemIndex.groupIndex property but it doesn't work !

    • Edited by Ruezaki Thursday, January 24, 2013 12:49 PM
    Thursday, January 24, 2013 12:12 PM
  • There is no groupIndex property.

    args.detail.itemIndex is an integer which gives you the index of the item based on the complete bound list. (Data.items).

    You should look carefully at the model to understand how it works. Look at the code below, and read my comments : 

          _itemInvoked: function (args) {
             if (appView.value === appViewState.snapped) {
                var group = Data.groups.getAt(args.detail.itemIndex);
                this.navigateToGroup(group.key);
             } else {
                // We retrieve the actual reference to the selected item
                var item = Data.items.getAt(args.detail.itemIndex);
                // In our model, each item has a group property, so you can retrieve it.
                var group = item.group;            
    
                nav.navigate("/pages/itemDetail/itemDetail.html", { item: Data.getItemReference(item) });
             }
          }

    Thee is no groupIndex property, but instead you have a key, that you can find with group.key.



    http://www.renauddumont.be

    • Marked as answer by Song Tian Tuesday, January 29, 2013 10:27 AM
    • Unmarked as answer by Ruezaki Tuesday, January 29, 2013 2:04 PM
    • Marked as answer by Ruezaki Tuesday, January 29, 2013 2:04 PM
    Sunday, January 27, 2013 10:05 AM
  • Thank you your comments are much helpful.
    Tuesday, January 29, 2013 2:07 PM