Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Tejas Shah on Sep 10, 2008 06:26
open dhtmlx forum
DHX Grid : Problem after Drag-n-Drop.

Hi there,
I am having all integer starting from 1 in first column of grid(thats default).
Also the row IDs are starting from 1.
When I do drag-n-drop, I want that data which is shown for first column should always start from 1 and so on..... (I have done this)
Also I want the id of the row not to change, means it should also be same as starting from 1 and so on even after drag-n-drop...........
How to achieve this ?
Answer posted by Support on Sep 10, 2008 06:40
>> it should also be same as starting from 1 and so on even after drag-n-drop
Technically it can be done as 
grid.attachEvent("onDrop",function(){
     for (var i=0; i<grid.getRowsNum(); i++)
         grid.setRowId(i,i+1);
});

each time after d-n-d , code will loop through grid and change IDs 
Answer posted by Tejas Shah on Sep 10, 2008 23:54
Hi there,
             I have written the code like following.
     
             libTableGrid.attachEvent("onDrop",function(){
                                                        for (var i=0; i<libTableGrid.getRowsNum(); i++)
                                                       {
                                                            var j = i+1;
                                                            libTableGrid.cells2(i,0).setValue(j);
                                                       }
                                                      
                                                        for (var i=0; i<libTableGrid.getRowsNum(); i++)
                                                             libTableGrid.setRowId(i,i+1);
                                    });   

                           Before doing d-n-d, I am able to get the CSV data of the grid, but after d-n-d, I am not able to get the CSV data.

                          Also whats the difference between
 
                          libTableGrid.cells2(i,0).setValue(j);
                          and
                          libTableGrid.cells(i,0).setValue(j);
                       
                          ?????           
             
Answer posted by Support on Sep 11, 2008 07:35
>>  Also whats the difference between 
cells use row ID as first parameter
cells2 use row Index as first parameter

>>  Before doing d-n-d, I am able to get the CSV data of the grid, but after d-n-d, I am not able to get the CSV data.
Problem confirmed,  you need to replace 
  for (var i=0; i<libTableGrid.getRowsNum(); i++)
  libTableGrid.setRowId(i,i+1);

with 

  for (var i=0; i<libTableGrid.getRowsNum(); i++)
  libTableGrid.setRowId(i,"a"+i);
  for (var i=0; i<libTableGrid.getRowsNum(); i++)
  libTableGrid.setRowId(i,i+1);