Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/01/2011, 12:57
imRicoh
 
Fecha de Ingreso: enero-2011
Mensajes: 49
Antigüedad: 13 años, 4 meses
Puntos: 0
Pregunta Drag and Drop de Filas en una Tabla

Manes como se hace para que las filas de una se puedan mover y rehubicar, me baje este codigo pero no funciona

Código HTML:
Ver original
  1. <head>    
  2.     <style type="text/css">
  3.         tr, tr td {
  4.             border: 1px #999999 solid;
  5.             border-bottom: 2px #999999 solid;
  6.             background-color: #FFFFFF;}
  7.         tr.underline, tr.underline td {
  8.             border-bottom: 2px #000000 solid;
  9.             background-color: #CCCCCC;}
  10.            
  11.     </style>
  12. <script type="text/javascript">
  13.     var draggingRow = false;
  14.     var sourceRow = null;
  15.     function startedDragging()
  16.     {
  17.         draggingRow = true;
  18.         sourceRow = event.srcElement.parentNode.parentNode;
  19.     }
  20.     function dragEnter()
  21.     {
  22.         if (draggingRow) window.event.returnValue = false;
  23.     }
  24.     function dragOver()
  25.     {
  26.         if (draggingRow)
  27.         {
  28.             var targetRow = event.srcElement;
  29.             while (targetRow.parentNode != null && targetRow.tagName && targetRow.tagName.toLowerCase() != 'tr')
  30.                 targetRow = targetRow.parentNode;
  31.             targetRow.className = 'underline';
  32.             window.event.returnValue = false;
  33.         }
  34.     }
  35.     function dragLeave()
  36.     {
  37.         if (draggingRow)
  38.         {
  39.             var targetRow = event.srcElement;
  40.             while (targetRow.parentNode != null && targetRow.tagName && targetRow.tagName.toLowerCase() != 'tr')
  41.                 targetRow = targetRow.parentNode;
  42.             targetRow.className = '';
  43.         }
  44.     }
  45.     function dropped()
  46.     {
  47.         if (draggingRow)
  48.         {
  49.             targetRow = event.srcElement;
  50.             while (targetRow.parentNode != null && targetRow.tagName && targetRow.tagName.toLowerCase() != 'tr')
  51.                 targetRow = targetRow.parentNode;
  52.             targetRow.className = '';
  53.             sourceRow.swapNode(targetRow);
  54.             draggingRow = false;
  55.         }
  56.     }
  57.     var iconForDragging = '#define icon_width 4\n#define icon_height 4\nstatic char icon_bits[] = { 0x05, 0x0A, 0x05, 0x0A };';
  58.  
  59. </head>
  60. <body ondrop="dropped();">
  61. <table id="dragDropTable" border="0" cellpadding="2" cellspacing="0">
  62.     <tr ondragenter="dragEnter();" ondragover="dragOver();" ondragleave="dragLeave();">
  63.         <td><img src="javascript:iconForDragging;" width="16" height="16" ondragstart="startedDragging();"></td>
  64.         <td>Row 0, Cell 1</td>
  65.         <td>Row 0, Cell 2</td>
  66.         <td>Row 0, Cell 3</td>
  67.     </tr>
  68.     <tr ondragenter="dragEnter();" ondragover="dragOver();" ondragleave="dragLeave();" ondrop="dropped();">
  69.         <td><img src="javascript:iconForDragging;" width="16" height="16" ondragstart="startedDragging();"></td>
  70.         <td>Row 1, Cell 1</td>
  71.         <td>Row 1, Cell 2</td>
  72.         <td>Row 1, Cell 3</td>
  73.     </tr>
  74.     <tr ondragenter="dragEnter();" ondragover="dragOver();" ondragleave="dragLeave();" ondrop="dropped();">
  75.         <td><img src="javascript:iconForDragging;" width="16" height="16" ondragstart="startedDragging();"></td>
  76.         <td>Row 2, Cell 1</td>
  77.         <td>Row 2, Cell 2</td>
  78.         <td>Row 2, Cell 3</td>
  79.     </tr>
  80. </body>
  81. </html>

Saludos