2012-01-19 14 views
0

ちょうど新しいプロジェクトに割り当てられていて、前にJavascriptを処理したことがない。現在、データは下のコードでグリッドの上下に移動します。 case文に "top"と "bottom"を追加する必要があります。これは、ユーザが選択した行をグリッドの上部または下部に移動させます。私はGoogle検索の答えをしようとしているが、多くの運がない。私がどこで私の検索を続けることができるかについてのアドバイスは役に立ちます。データを上端または下端に移動する

確認新しい問題。私が作成したコードをいくつか追加しました。 case文の "top"と "bottom"にあります。私が追加したコードでは、項目を選択してリストの一番上に移動することができます。しかし、IEを下に移動すると、IEはスクリプトが長くかかると言います。何かアドバイス?

私はコードを動かすことはありません。以下は作業コードです。既存のコードで

function move(direction) { 
try { 
    if (CSAdmin.selectedItem.element && 
CSAdmin.selectedItem.ID) { 
     var row = CSAdmin.selectedItem.element; 
     var node = 
    getNode(CSAdmin.selectedItem.type, CSAdmin.selectedItem.ID); 
     if (node) { 
      var sibling = null; 
      var rowSibling = null; 
      var parent = node.parentNode; 
      var rowParent = row.parentNode; 
      switch (direction) { 
       case "up": 
        { 
         sibling = node.previousSibling; 
         if (sibling) { 
          parent.removeChild(node); 
          parent.insertBefore(node, sibling); 
         } 
         //Move the table row 
         rowSibling = row.previousSibling; 
         if (rowSibling) { 
          rowParent.removeChild(row); 
          rowParent.insertBefore(row, rowSibling); 
         } 
         break; 
        } 
       case "down": 
        { 
         sibling = node.nextSibling; 
         if (sibling) { 
          parent.removeChild(sibling); 
          parent.insertBefore(sibling, node); 
         } 
         //Move the table row if it isn't the insert row 
         rowSibling = row.nextSibling; 
         if (rowSibling && rowSibling.id.indexOf("new", 0) == -1) { 
          rowParent.removeChild(rowSibling); 
          rowParent.insertBefore(rowSibling, row); 
         } 
         break; 
        } 
        case "top": 
        { 
         sibling = node.previousSibling; 
         while (sibling) { 
          if (sibling) { 
           parent.removeChild(node); 
           parent.insertBefore(node, sibling); 
           sibling = node.previousSibling; 
          } 
         } 
         //Move the table row 
         rowSibling = row.previousSibling; 
         while (rowSibling) { 
          if (rowSibling) { 
           rowParent.removeChild(row); 
           rowParent.insertBefore(row, rowSibling); 
           rowSibling = row.previousSibling; 
          } 
         } 
         break; 
        } 
       case "bottom": 
        { 
         sibling = node.nextSibling; 
         while (sibling) { 
          if (sibling) { 
           parent.removeChild(sibling); 
           parent.insertBefore(sibling, node); 
           sibling = node.nextSibling; 
          } 
         } 
         //Move the table row if it isn't the insert row 
         rowSibling = row.nextSibling; 
         while (rowSibling && rowSibling.id.indexOf("new", 0) == -1) { 
          if (rowSibling && rowSibling.id.indexOf("new", 0) == -1) { 
           rowParent.removeChild(rowSibling); 
           rowParent.insertBefore(rowSibling, row); 
           rowSibling = row.nextSibling; 
          } 
         } 
         break; 
        } 
      } 
     } 
    } 
} 
catch (err) { 
    throw new Error("Error moving row:" + err.description); 
} 
+0

私は本当にあなたの質問を理解していません。あなたが達成しようとしているもの/既に持っているものの例を加えてください。 –

+0

私が持っているのは、DataGridです。行を選択して[上へ]または[下へ]ボタンを押すと、一度に1行ずつ上下に移動できます。私はその行をグリッドの最上部または最下部のいずれかに移動する「Move To Top」および「Move To Bottom」ボタンを追加します。上記のコードは現在、一度に1行上または下に移動します。 – cjohnson2136

答えて

1

変数名は一種の(あなたもnodeが何であるかを教えていない)混乱しているが、これはそれを動作させるための基本的な前提です。この例では、jQueryを使用して作業をショートカットしましたが、ロジックは健全で、jQueryに依存しません。下へ移動

http://jsfiddle.net/qukDJ/

//move to top 
var currentRow = $(this).closest('tr')[0];  
var firstRow = currentRow.parentNode.childNodes[0]; 
currentRow.parentNode.insertBefore(currentRow, firstRow); 

基本的にあなたがLASTROWとinsertAfterをしたい除いて、同じことです。

var lastRow = currentRow.parentNode.childNodes[currentRow.parentNode.childNodes.length - 1]; 
currentRow.parentNode.insertAfter(currentRow, lastRow); 
+0

混乱して申し訳ありませんが、これは私のコードではありません。それはもはやここにない開発者に属します。私はすべて自分でそれを把握しようとしています。私が言うことができるから、ノードは薄くて、selectedItemの型とIDです。私はこれを基にしています。var node = getNode(CSAdmin.selectedItem.type、CSAdmin.selectedItem.ID); – cjohnson2136

+0

これは正確な正解ではありませんが、それはjavascriptが何をしているのか把握することができ、それを正しく行う方法を実現することを可能にしました。 – cjohnson2136

関連する問題