This is a migrated thread and some comments may be shown as answers.

Use copy while performing item transfer among 7 radlistboxs

3 Answers 42 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Abhishek
Top achievements
Rank 1
Abhishek asked on 22 Dec 2011, 02:01 PM
Hi,
i am performing transfer among 7 radlistboxs on OnClientDropped event using "transferManager.performTransfer" method in javascript .

 

<script id="ListBoxItemTransfer" type="text/javascript">

 

function lbdropped(sender, args) {

sender.trackChanges();

 

var destinationListBox = transferManager.performTransfer(sender, args);

sender.commitChanges();

 

//Call back function

 

var senderListboxId = sender.get_id();

 

if (senderListboxId == 'rlbFuncImprovement' || senderListboxId == 'rlbTechImprovement' || senderListboxId == 'rlbConsolidation') {

 

var objectIds = '';

 

var items = args.get_sourceItems();

 

var i = 0;

 

for (i = 0; i < items.length; i++) {

 

if (objectIds == '') {

objectIds = items[i].get_value();

}

 

else {

objectIds = objectIds +

 

',' + items[i].get_value();

}

}

 

var arrgument = senderListboxId + ',' + objectIds + ", 0";

CallServer(arrgument,

 

'');

}

}

 

//Multi-list box transfer generic code

(

 

function ($) {

transferManager =

 

function () { }

transferManager.performTransfer =

 

function (sender, args) {

 

var destinationItemIndex = this._getDestinationIndex(args);

 

var destinationListBox = this._getDestinationListBox(args);

 

if (destinationListBox == null || destinationListBox.get_id() == document.getElementById('rlbProposed').id)

 

return;

 

var reorderIndex = args.get_dropPosition() == 0 ?

destinationItemIndex : destinationItemIndex + 1;

 

var items = args.get_sourceItems();

 

this._transfer(items, destinationListBox, reorderIndex);

 

return destinationListBox;

}

transferManager._transfer =

 

function (items, destination, reorderIndex) {

$.each(items,

 

function (index, item) {

destination.trackChanges();

destination.get_items().insert(reorderIndex, item);

destination.commitChanges();

});

}

transferManager._getDestinationIndex =

 

function (args) {

 

var destinationItem = args.get_destinationItem();

 

if (destinationItem)

 

return destinationItem.get_index();

 

return 0;

}

transferManager._getDestinationListBox =

 

function (args) {

 

var destinationItem = args.get_destinationItem();

 

if (destinationItem) {

 

var id = destinationItem.get_listBox().get_id();

 

return $find(id);

}

 

var parent = $(args.get_htmlElement()).parent();

 

if (parent.is(".RadListBox")) {

 

var id = parent[0].id;

 

return $find(id);

}

 

else if (parent.is(".rlbGroup")) {

 

var id = parent[0].parentNode.id;

 

return $find(id);

}

 

return null;

}

})($telerik.$);

 

</script>



I want that First listbox do the copy item functionality to other listbox, whereas other listboxs do the move item functionality.
How can i achieve this?

3 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 26 Dec 2011, 01:12 PM
Hi,

To achieve the desired functionality, you have to modify the code before the following line - destination.get_items().insert(reorderIndex, item). The nature of the insert() function used is that it takes the source item and it deletes it from its listbox. So to implement a copy, you have to pass a copy of the item to the function.

I've modified two of your functions to make everything work as desired. Here are the modified versions:

transferManager.performTransfer = function (sender, args) {
    var destinationItemIndex = this._getDestinationIndex(args);
    var destinationListBox = this._getDestinationListBox(args);
    if (destinationListBox == null)
        return;
    var reorderIndex = args.get_dropPosition() == 0 ? destinationItemIndex : destinationItemIndex + 1;
    var items = args.get_sourceItems();
    this._transfer(items, destinationListBox, reorderIndex, sender);
    return destinationListBox;
}
 
transferManager._transfer = function (items, destination, reorderIndex, sender) {
    $.each(items, function (index, item) {
        destination.trackChanges();
        if (sender.get_id()=="copyListBox")
            var item = item.clone();
        destination.get_items().insert(reorderIndex, item);
        destination.commitChanges();
    });
}

 

All the best,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Abhishek
Top achievements
Rank 1
answered on 03 Jan 2012, 08:05 AM
Hi,
Thanks for reply.Copy function started working with following new bugs.
1. Duplicate item is being transfered.
2. I have no way ro remove items once transfered from main listbox. How to remove items?
0
Bozhidar
Telerik team
answered on 03 Jan 2012, 05:08 PM
Hi Abhishek,

If I understand your first question correctly, you don't want to allow transfer of the same item twice in one destination listbox. Here's what you have to change in your code to accomplish that:

transferManager._transfer = function (items, destination, reorderIndex, sender) {
    $.each(items, function (index, item) {
        destination.trackChanges();
        if (sender.get_id()=="RadListBox1") {
            if (destination.get_items().find(function(destItem) { return destItem.equals(item); })) return true;
            var item = item.clone();
        }
        destination.get_items().insert(reorderIndex, item);
        destination.commitChanges();
    });
}

To remove an item from any listbox, just use the remove() method of the client RadListBoxItemCollection object. You can read more about how to manipulate the RadListBoxItemCollection here.

Regards,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
ListBox
Asked by
Abhishek
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Abhishek
Top achievements
Rank 1
Share this question
or