Search code examples
javascriptwindows-8visual-studio-2012microsoft-metrowinjs

how to invoke a ListView from a ListItem


I want to update the right listview when I any item from the right list Also when I click select all items to select the right list items not the left items.

in other words what I want to do is that when I click any item in the left list the right list will change according to the left item I Invoked to a diiferent list

enter image description here

here is my JS code

function selectionChangedHandler() {

    // Check for selection
    var selectionCount = listView.selection.count();
    if (selectionCount === 1) {

        // Only one item is selected, show the message
        // information for the item
        listView.selection.getItems().done(function (items) {
            // Print item data to the relevant message pane locations
            inboxMessage_Text.innerText = items[0].data.text;
            if (items[0].data.key == 1) {
                document.getElementById('listView4b2')
                        .innerHTML = '<ol><li>html2222 data</li></ol>';
            } else {
                document.getElementById('listView4b2')
                        .innerHTML = '<ol><li>html data</li></ol>';
            }
        });

    }

}
function selectAll() {
    WinJS.log && WinJS.log(" ", "sample", "status");
    listView.selection.selectAll();
}

function clearSelection() {
    WinJS.log && WinJS.log(" ", "sample", "status");
    listView.selection.clear();
}

and HTML code

<div id="listView4b"
    class="win-selectionstylefilled"
    data-win-control="WinJS.UI.ListView" 
    data-win-options="{ 
        itemDataSource: myToppingsData.dataSource, 
        itemTemplate: mediumListIconTextTemplate, 
        selectionMode: 'multi', 
        tapBehavior: 'toggleSelect', 
        layout: { type: WinJS.UI.GridLayout } 
    }"
></div>

Solution

  • Assuming that myToppingsData is a WinJS.Binding.List, in the itemInvoked handler of the left WinJS.UI.ListView create a projection on this list using createFiltered.

    You can then set the itemDataSource of the list on the right to this filtered lists dataSource.