Loading ...
Sorry, an error occurred while loading the content.
 

Move rows from one datatable to another and KeyListener problemer

Expand Messages
  • casperskovgaard
    I have two datatables, in dt1 you can select a row and press [space], and the row is move to dt2. This is done by first dt2.addRow and then dt1.deleteRow.
    Message 1 of 2 , Oct 15, 2008
      I have two datatables, in dt1 you can select a row and press [space],
      and the row is move to dt2. This is done by first dt2.addRow and then
      dt1.deleteRow. Since the selected row is deleted I select the next row
      in dt1. This works, the problem is that nothing happens if I press
      [space] again. To move the next row I first have to select another and
      then select it again.

      here is the move code:

      var selectedRows = availableDT.getSelectedRows();
      var selectedIndex = 0;

      for (var i=0; i<selectedRows.length; i++) {
      selectedIndex = availableDT.getRecordIndex(selectedRows[i]);
      selectedDT.addRow(availableDT.getRecord(selectedIndex).getData());

      availableDT.deleteRow(selectedRows[i]);
      }

      if (availableDT.getRecordSet().getLength() <= selectedIndex) {
      selectedIndex = availableDT.getRecordSet().getLength() - 1;
      }

      availableDT.selectRow(availableDT.getTrEl(selectedIndex));
      availableDT.focus();


      full code example can be downloaded here:
      http://www.box.net/shared/km0qq3q1vv
    • jennykhan
      Hi casperskovgaard, In line 144, just change availableDT.selectRow(availableDT.getTrEl(selectedIndex)); to availableDT.unselectAllRows();
      Message 2 of 2 , Dec 1, 2008
        Hi casperskovgaard,

        In line 144, just change

        availableDT.selectRow(availableDT.getTrEl(selectedIndex));

        to

        availableDT.unselectAllRows();
        availableDT.selectRow(availableDT.getTrEl(selectedIndex));

        Regards,
        Jenny



        --- In ydn-javascript@yahoogroups.com, "casperskovgaard"
        <casperskovgaard@...> wrote:
        >
        > I have two datatables, in dt1 you can select a row and press
        [space],
        > and the row is move to dt2. This is done by first dt2.addRow and
        then
        > dt1.deleteRow. Since the selected row is deleted I select the next
        row
        > in dt1. This works, the problem is that nothing happens if I press
        > [space] again. To move the next row I first have to select another
        and
        > then select it again.
        >
        > here is the move code:
        >
        > var selectedRows = availableDT.getSelectedRows();
        > var selectedIndex = 0;
        >
        > for (var i=0; i<selectedRows.length; i++) {
        > selectedIndex = availableDT.getRecordIndex
        (selectedRows[i]);
        > selectedDT.addRow(availableDT.getRecord
        (selectedIndex).getData());
        >
        > availableDT.deleteRow(selectedRows[i]);
        > }
        >
        > if (availableDT.getRecordSet().getLength() <= selectedIndex)
        {
        > selectedIndex = availableDT.getRecordSet().getLength
        () - 1;
        > }
        >
        > availableDT.selectRow(availableDT.getTrEl(selectedIndex));
        > availableDT.focus();
        >
        >
        > full code example can be downloaded here:
        > http://www.box.net/shared/km0qq3q1vv
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.