2011-08-25 88 views
0

我想使用jquery sortable,當一個項目被移動,它然後更新隱藏的排序字段?有沒有人做過這個?我嘗試了一些不同的東西,但它沒有通過該項目的當前順序。jquery sortable,更新排序字段

這裏是我的代碼:

jQuery(document).ready(function() { 
    jQuery(".sortable").sortable({ 
    opacity: 0.6, 
    cursor: 'move', 
    update: function(event, ui) { 
     var ordering = $(this).sortable('toArray').toString(); 
     alert(ordering); 
    } 
    }); 
}); 

這是我的表的排序部分:

<tbody class="sortable ui-sortable"> 
    <tr> 
    <td width="5" align="center" class="cols sort">&nbsp;</td> 
    <td align="left"><a onclick="getUsrInfo(1)" class="__productTBLink"><strong>Leanne Seawright</strong>, Web Designer <span class="__rowShowInfo">- view info.</span></a></td> 
    <td width="20" align="center"><a class="__productTBLink" onclick="javascript:confdelete(1);"><img width="16" height="16" align="left" title="Delete - click to delete this user" alt="Edit" src="/templates/manufacturers/images/delete.png"></a><input type="text" value="1" id="ordering[1]" name="ordering"></td> 
    </tr> 
    <tr> 
    <td width="5" align="center" class="cols sort">&nbsp;</td> 
    <td align="left"><a onclick="getUsrInfo(2)" class="__productTBLink"><strong>George Jetson</strong>, Driver <span class="__rowShowInfo">- view info.</span></a><input type="text" value="2" id="ordering[2]" name="ordering"></td> 
    <td width="20" align="center"><a class="__productTBLink" onclick="javascript:confdelete(2);"><img width="16" height="16" align="left" title="Delete - click to delete this user" alt="Edit" src="/templates/manufacturers/images/delete.png"></a></td> 
    </tr> 
</tbody> 

我只想輸入域「命令」項目時使用jQuery移動進行更新排序。

在此先感謝:)

回答

3

你應該給你的tr。的id。這裏是一個​​

<tbody class="sortable ui-sortable"> 
    <tr id="1"> 
    <td width="5" align="center" class="cols sort">&nbsp;</td> 
    <td align="left"><a onclick="getUsrInfo(1)" class="__productTBLink"><strong>Leanne Seawright</strong>, Web Designer <span class="__rowShowInfo">- view info.</span></a></td> 
    <td width="20" align="center"><a class="__productTBLink" onclick="javascript:confdelete(1);"><img width="16" height="16" align="left" title="Delete - click to delete this user" alt="Edit" src="/templates/manufacturers/images/delete.png"></a><input type="text" value="1" id="ordering[1]" name="ordering"></td> 
    </tr> 
    <tr id="2"> 
    <td width="5" align="center" class="cols sort">&nbsp;</td> 
    <td align="left"><a onclick="getUsrInfo(2)" class="__productTBLink"><strong>George Jetson</strong>, Driver <span class="__rowShowInfo">- view info.</span></a><input type="text" value="2" id="ordering[2]" name="ordering"></td> 
    <td width="20" align="center"><a class="__productTBLink" onclick="javascript:confdelete(2);"><img width="16" height="16" align="left" title="Delete - click to delete this user" alt="Edit" src="/templates/manufacturers/images/delete.png"></a></td> 
    </tr> 
</tbody> 
+0

該死的,我的「有1個新的迴應」警告在這個職位? +1,擊敗我。 –