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

Copy some selected rows from one grid to another grid

7 Answers 1596 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sourav
Top achievements
Rank 1
Sourav asked on 31 Oct 2011, 02:45 PM
In grid there have some multiple records. Now I am selecting some rows. I want to copy only those selectable rows in another grid.
How I can do this. Please help.

Thanks in advance.

7 Answers, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
answered on 30 Mar 2012, 03:00 PM
Has anyone implemented this? I am looking for the same thing.

Thank you in advance.
0
Marko
Top achievements
Rank 1
answered on 02 Apr 2012, 08:59 AM
I am looking for the same thing too.

-Marko
0
Paul
Top achievements
Rank 1
answered on 02 Apr 2012, 01:42 PM
I figured it out. With multiselect you can't do drag and drop, so you'll have to use a click event to copy the selected rows from one grid to another. Here's the javascript code:

        $('#btnAddMulti').click(function () {
 
            var sourcegrid = $('#searchgrid').data('kendoGrid');        //SOURCE GRID
            var destinationgrid = $('#selectedgrid').data('kendoGrid'); // DESTINATION GRID
 
            sourcegrid.select().each(function () {
                var dataItem = sourcegrid.dataItem($(this));
                destinationgrid.dataSource.add(dataItem);       // DESTINATION DATASOURCE
            });
            destinationgrid.refresh();                          // MUST REFRESH THE DESTINATION GRID
            alert('refreshed');
 
        });

I hope this helps.
0
Marko
Top achievements
Rank 1
answered on 03 Apr 2012, 07:34 AM
Hi,

Thanks Paul for example, it works.

Is it possible to avoid duplicates (liike. same product name) in destination grid? So, that items can be copied only once. In asp.net I'm using Insert event to check if item already exists.

-Marko
0
Paul
Top achievements
Rank 1
answered on 03 Apr 2012, 02:44 PM
Marko, I just implemented this as well, it's pretty easy:

           $('#btnAddMulti').click(function () {
 
               var sourcegrid = $('#searchgrid').data('kendoGrid');        //SOURCE GRID
               var destinationgrid = $('#selectedgrid').data('kendoGrid'); // DESTINATION GRID
 
               sourcegrid.select().each(function () {
                   var dataItem = sourcegrid.dataItem($(this));

                   //*******************
                   // Check to make sure it's not in there
                   var column = dataItem.ProductId; // whatever the name of the unique id for your data source                    if (destinationgrid.dataSource.get(column) == null)                        destinationgrid.dataSource.add(dataItem);       // DESTINATION DATASOURCE
            	   else
                	alert('already exists');
                   //*******************
               });                destinationgrid.refresh();                          // MUST REFRESH THE DESTINATION GRID                alert('refreshed');            }); Here's my data source to see the "ProductId":            var dataSource = new kendo.data.DataSource({                data: data.datalist,                schema: {                    model: {                        id: "ProductId",                        fields: {                            ProductId: { type: 'int', nullable: false },                            ProductName: { type: 'string', editable: false, nullable: true }                        }                    }                }            });
0
Ricardo
Top achievements
Rank 1
answered on 03 Apr 2012, 03:10 PM
is not my post but thanks, I served a lot of your example
0
jonathan
Top achievements
Rank 1
answered on 30 Oct 2012, 02:30 PM
Hey guys,

I have implemented your above example, but am editing the destination grid by cell.  When you edit a cell in the destination grid, it updates the source as well.  Is there a way around this?
Tags
Grid
Asked by
Sourav
Top achievements
Rank 1
Answers by
Paul
Top achievements
Rank 1
Marko
Top achievements
Rank 1
Ricardo
Top achievements
Rank 1
jonathan
Top achievements
Rank 1
Share this question
or