locked
How to INSERT an Item at some index in WinJS.Binding.List ? RRS feed

  • Question

  • Hi,

       how to insert an Item in middle/ at specified index in WinJS.Binding.List ?

    Thanks

    Tuesday, May 14, 2013 7:50 AM

Answers

  • Hi,

    unfortunately I think that's not directly supported. The only way that I know of to get data into the binding list is to use the push method which always adds to the end.

    However: You could use the createSorted method of the binding list to create a live sorted projection over your list. This projection updates itself when you change the underlying list. So if you have your own key that you can sort by, you could simulate to "insert an item in the middle" by creating a sorted projection and assigning the right key to your new item.

    Tuesday, May 14, 2013 8:03 AM

All replies

  • Hi,

    unfortunately I think that's not directly supported. The only way that I know of to get data into the binding list is to use the push method which always adds to the end.

    However: You could use the createSorted method of the binding list to create a live sorted projection over your list. This projection updates itself when you change the underlying list. So if you have your own key that you can sort by, you could simulate to "insert an item in the middle" by creating a sorted projection and assigning the right key to your new item.

    Tuesday, May 14, 2013 8:03 AM
  • list.push(item);
    list.move(list.length - 1, 0);
    Friday, December 12, 2014 1:51 PM