locked
How to delete a item for custom datasource of listview?

    Question

  • I've been trying to get a WinJS.UI.ListView to work with a custom data source and I have followed the instructions here. But both the samples and instructions did not tell how to add or delete a item in customize datasource. Could you kindly help me? Thanks very much.

    Friday, June 08, 2012 9:52 AM

Answers

  • Hi

    Does this isn't your need?

    http://code.msdn.microsoft.com/windowsapps/ListView-custom-data-4dcfb128

    I think this codes had show you how to delete a item in customize datasource.

    function removeSelected() {
            // Get the control, itemDataSource and selected items
            var list2 = document.getElementById("listView3").winControl;
            var ds = list2.itemDataSource;
    
            if (list2.selection.count() > 0) {
                list2.selection.getItems().done(function (items) {
    
                    // Start a batch for the edits
                    ds.beginEdits();
    
                    // To remove the items, call remove on the itemDataSource passing in the key
                    items.forEach(function (currentItem) {
                        ds.remove(currentItem.key);
                        ds.remove
                    });
    
                    // End the batch of edits
                    ds.endEdits();
                });
            }
        }

    Monday, June 11, 2012 3:12 AM