2

テーブルの行を並べ替えて、テーブル行の「子」要素として配置しようとしています

私はこれを見つけました:http ://code.google.com/p/nestedsortables/これはul liリストで機能しますが、テーブル用に作成したいと思います。

<table>
  <thead>
    <th>tablehead</th>
  </thead>
  <tbody>
    <tr><td>somevalue</td></tr>
    <tr><td>somevalue2</td></tr>
  </tbody>
</table>

したがって、行を使用して並べ替えることはできますがjquery.sortable()、「somevalue」を「somevalue2」の上にドラッグすると、「somevalue」が「somevalue2」の子要素になります。

テーブルで可能かどうかはわかりません。

誰か助けてもらえますか?

4

1 に答える 1

3

さて、私はこのプラグインを見つけました:http: //ludo.cubicphuse.nl/jquery-plugins/treeTable/doc/index.html#example-1

これはテーブルを使用し、ネストできるようにします。

これで、それを並べ替えて、親IDを使用してテーブル要素をポスト送信する必要があります。これにより、データベースに保存できます。

これが他の誰かに役立つことを願っています。

これが私が思いついたものです。2レベル(親と子のみ)を超えたくないので、親が子のみを受け入れるように変更し、親をドラッグ可能にしないようにしました。

<html>
    <head>
        <link href="jquery.treeTable.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="jquery-ui.js"></script>
        <script type="text/javascript" src="jquery.treeTable.js"></script>
        <script type="text/javascript">

    $(document).ready(function()  {
        $("#dragndrop").treeTable();

        // Drag & Drop Code
        $("#dragndrop .child").draggable({
          helper: "clone",
          opacity: .75,
          refreshPositions: true, // Performance?
          revert: "invalid",
          revertDuration: 300,
          scroll: true
         }
        );

        $("#dragndrop .parent").each(function() {
          $($(this).parents("tr")[0]).droppable({
            accept: ".child",
            drop: function(e, ui) {
              $($(ui.draggable).parents("tr")[0]).appendBranchTo(this);
              setNewParent($($(ui.draggable).parents("tr")[0]).attr("id"), $(this).attr("id"));
            },
            hoverClass: "accept",
            over: function(e, ui) {
              if(this.id != $(ui.draggable.parents("tr")[0]).id && !$(this).is(".expanded")) {
                $(this).expand();
              }
            }
          });
        });

        function setNewParent(child, parent)
        {
            // do ajax call here
            alert(child);
            alert(parent);
        }
    });

    </script>
</head>
<body>

    <table id="dragndrop">
      <thead>
        <tr> 
          <th>Title</th>
          <th>Size</th>
          <th>Kind</th>
        </tr>
      </thead>
      <tbody>
        <tr id="node-1">
          <td><span class="parent">CHANGELOG</span></td>
          <td>4 KB</td>
          <td>Parent</td>
        </tr>

        <tr id="node-3" class="child-of-node-1">
          <td><span class="child">images</span></td>
          <td>--</td>
          <td>child</td>
        </tr>

        <tr id="node-2">
          <td><span class="parent">doc</span></td>
          <td>--</td>
          <td>Parent</td>
        </tr>

        <tr id="node-4" class="child-of-node-2">
          <td><span class="child">bg-table-thead.png</span></td>
          <td>52 KB</td>
          <td>child</td>
        </tr>

        <tr id="node-5" class="child-of-node-2">
          <td><span class="child">folder.png</span></td>
          <td>4 KB</td>
          <td>child</td>
        </tr>

      </tbody>
    </table>
</body>

テーブル全体を並べ替え可能にするには、jQueryの.sortable()関数を使用できますが、わかりやすくするために、ここでは省略しました。

于 2010-03-15T11:10:21.893 に答える