Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Alistair Macneil on Sep 22, 2008 16:42
open dhtmlx forum
gridToGrid

Hi there,

I would like to use the gridtogrid function to copy the necessary columns to mygrid2 when

<a href="javascript:mygrid2.gridToGrid(mygrid.getSelectedId(),mygrid,mygrid2)=function(){
return [mygrid.cells(mygrid.getSelectedId(),0).getValue(),mygrid.cells(mygrid.getSelectedId(),1).getValue(),"","","","",""];
});
">Add</a>

is clicked.

I am using mygrid to display products and mygrid2 to act as the shopping cart but cant get the gridtogrid working
Answer posted on Sep 23, 2008 01:32

This function is used by drag-n-drop functionality but doesn't do anything itself. So it should be redefined but not called to copy rows.

 

mygrid2.gridToGrid = function(rowId,sGrid,tGrid){
   return [sGrid.cells(rowId,0).getValue(),sGrid.cells(rowId,1).getValue(),"","","","",""];
};

After this using drag-n-drop you'll get results as expacted. Or you can use moveRow method to move row programatically:

<a href="javascript:mygrid.moveRow(mygrid.getSelectedId(),'row_sibling',mygrid2.getSelectedId(),mygrid2)">Move It</a>

Answer posted by Alistair Macneil on Sep 23, 2008 07:47
Thanks,

I have added the code in to the xml of the grid to get it to work as an add to cart link, which adds that row (product) to the 2nd grid (shopping cart)
                print("<cell><![CDATA[<a href=\"javascript:mygrid.moveRow(mygrid.getSelectedId(),'row_sibling',mygrid2.getSelectedId(),mygrid2)\">Add</a>]]></cell>");
How can I change that last cell to this
<a href=\"javascript:mygrid2.moveRow(mygrid2.getSelectedId(),'row_sibling',mygrid.getSelectedId(),mygrid)\">Delete</a>
so that I can remove items from the shopping cart?

Answer posted by Alistair Macneil on Sep 23, 2008 14:57
I managed this with the following function:

    mygrid2.attachEvent("onRowAdded",function(rowid)
    {
         mygrid2.cells(rowid,10).setValue("<a href=\"javascript:mygrid2.moveRow(mygrid2.getSelectedId(),'row_sibling',mygrid.getSelectedId(),mygrid)\">Del</a>")
         return true;
    })