Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Cathy on Sep 11, 2008 09:47
open dhtmlx forum
is there any way to get the values of selected rows to an array

Hi

I have 120 rows in grid if i am selecting rows 3,4,5 is there any way to get the values of selected rows to an array. if i can get this in a array i will remove all image tags in it & reconstruct the array with only cell values

EG:- If i copy to clipboard i get it like this
<A onclick=javascript:NewWin()&gt;
<IMG src='file:///P:/WORKS/NEHI/TestGrid/Images/dyn_down.gif'&gt;
</A&gt;
George Micheal,Album Name,123.456.7890,,
<A href='george@george.com'&gt;george@george.com</A&gt;

I want to change it to like

George Micheal Album Name 123.456.7890 george@george.com

Thanks for your time
Cathy
 

Answer posted by Support on Sep 12, 2008 03:56
There is no native method to get values as an array, but can be done as
var ids = grid.getSelectedRowId().split(",");
var values=[]
for (var i=0; i<ids.length; i++)
    values.push( grid.cells(ids[i],INDEX).getValue());
//  values.push( grid.cells(ids[i],INDEX).getValue().toString().replace(/<[^>]*>/g,""));

where INDEX - index of column, from which data need to be taken  
Answer posted by Cathy on Sep 12, 2008 04:29
Hi

This one not at all working when i try this in tree grid i am getting 2 errors

1) "mygrid.getSelectedRowId() is null or not an object"
2) still in clipboard its coming as <A onclick=javascript:NewWin()><IMG src='file:///P:/WORKS/NEHI/TestGrid/Images/dyn_down.gif'></A>
George Micheal,Album Name,123.456.7890,,<A href='mailto:george@george.com'&gt;george@george.com</A>

i have row ids for all rows but in some rows there are no album name is that a issue.

here is my code please correct me if i am wrong

function onKeyPressed(code,ctrl,shift)
{   

    if(code==67&&ctrl)
    {
        var ids = mygrid.getSelectedRowId().split(",");
        var values=[]
        for (var i=0; i<ids.length; i++)
        values.push( mygrid.cells(ids[i],0).getValue());
        mygrid.copyBlockToClipboard();
       
    }
       
    if(code==86&&ctrl)
    {
        mygrid.pasteBlockFromClipboard();
    }
       
    return true;
}

Answer posted by Support on Sep 12, 2008 08:03
Please check attached sample
Attachments (1)
Answer posted by Support on Sep 12, 2008 08:05
In case of   mygrid.copyBlockToClipboard(); you can try next code

  if(code==67&&ctrl)
  {
  mygrid.copyBlockToClipboard();
  var text  = mygrid.fromClipBoard();
   text = text.replace(/<[^>]*>/g,"")
   mygrid.toClipBoard(text);
  }
   

Answer posted by cathy on Sep 12, 2008 08:34
nice its working

is there any way to get number of multiple columns selected instead of 1
Answer posted by Support on Sep 12, 2008 10:18
You can run the same code snippet few times, with different INDEX values
Answer posted by Cathy on Sep 12, 2008 10:23
Hi

Is there any way to do the following

1) get the number of rows selected
2) get the number of columns selected

so i can run a loop to get the values later i can concatenate everything 
Answer posted by Support on Sep 12, 2008 10:39
>>1) get the number of rows selected
>>2) get the number of columns selected
You can get details about block selection as 
  grid._selectionArea.LeftTopRow
  grid._selectionArea.LeftTopCol
  grid._selectionArea.RightBottomRow
  grid._selectionArea.RightBottomCol


Answer posted by Cathy on Sep 13, 2008 01:59
Hi thanks for your reply now its working fine with the following code am pasting it here so it may be useful to someone in future. i have one more doubt suppose if there are any blank columns or if i want to skip any row dynamically how should i do

here is my code

function onKeyPressed(code,ctrl,shift)
{   

    if(ctrl&&code==67)
    {       
   
        var RowStart = mygrid._selectionArea.LeftTopRow;
        var RowEnd = mygrid._selectionArea.RightBottomRow;
        var ColStart = mygrid._selectionArea.LeftTopCol;
        var ColEnd = mygrid._selectionArea.RightBottomCol;
        var values=[];
        for(var RowCnt=RowStart; RowCnt <=RowEnd; RowCnt++)
        {

            for(var ColCnt=ColStart; ColCnt <=ColEnd; ColCnt++)
            {
                values.push(mygrid.cells2(RowCnt,ColCnt).getValue().toString().replace(/<[^>]*>/g,""));                mygrid.toClipBoard(values.join(","))
            }   

        }
      }
       
    if(ctrl&&code==86)
    {
       
        mygrid.pasteBlockFromClipboard();
    }
       
    return true;
}