문제

I have a listbox with several listitems, I post one for example:

var listboxChooseColumns = new sap.ui.commons.ListBox("chooseColumns", {
    allowMultiSelect: true,
    items: [
        nameItem,
        new sap.ui.core.ListItem({
            text: "Functional Location",
            test: "lastName"   
        })
    ]
})

The listitems from one box can be moved to another one:

var moveAllToTableColumn = new sap.ui.commons.Button({
        press: function() {
            //var selectedItems = listboxChooseColumns.getSelectedItems();
            var selectedItems = listboxChooseColumns.getItems();
            for (var i=0; i<selectedItems.length;i++) {
                var listItem = selectedItems[i];
                listBoxChosenColumns.addItem(listItem);   
            }
        }
});  

If I want to bring the item back from the second list to the first one, the item goes to the end of the list, not in its initial position.

var moveFromTableColumn = new sap.ui.commons.Button({
    press: function(){
        var selectedItems = listBoxChosenColumns.getSelectedItems();
        for (var i=0; i<selectedItems.length;i++) {
            var listItem = selectedItems[i];
            listBoxChosenColumns.removeItem(listItem);
            listboxChooseColumns.addItem(listItem);   
        }
    }
});

How can I return item from the second list to the first list into initial position?

도움이 되었습니까?

해결책

Instead of addItem(), consider using insertItem(oItem, iIndex) which allows you to position the item being inserted (e.g. at the top, if you specify 0 for iIndex):

listboxChooseColumns.insertItem(listItem, 0);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top