我有一個使用jQuery UI sortable
函數的可拖動行的HTML表。它有一個顯示行號的索引列。按鈕點擊後jQuery函數不會觸發,但對其他事件不會觸發
如果用戶從表底部拖動一行到頂部,行號列中的值將更新以顯示正確的值。目前這工作正常。
我現在希望能夠點擊插入行並重新計算表中所有行的行號的按鈕。
我已經能夠將行添加到表的頂部,但行號不會更新,直到另一個事件被觸發爲止,例如將行拖入新位置或再次單擊該按鈕。
查看下面我的代碼,非常感謝任何幫助。
HTML
<table id="sort" class="grid">
<thead>
<tr><th class="index">Index</th><th>Name</th></tr>
</thead>
<tbody>
<tr><td class="index">1</td><td>Zippy</td></tr>
<tr><td class="index">2</td><td>George</td></tr>
<tr><td class="index">3</td><td>Bungle</td></tr>
<tr><td class="index">4</td><td>Geoffrey</td></tr>
</tbody>
</table>
jQuery的
$(document).ready(function() {
$("#sort tbody").sortable({
helper: fixHelperModified,
stop: updateIndex
}).disableSelection();
var fixHelperModified = function (e, tr) {
var $originals = tr.children();
var $helper = tr.clone();
$helper.children().each(function (index) {
$(this).width($originals.eq(index).width())
});
return $helper;
},
updateIndex = function (e, ui) {
$('td.index', ui.item.parent()).each(function (i) {
$(this).html(i + 1);
});
};
$('#AddRowButton').click(function() {
var newRow = '<tr><td class="index">1</td><td>New Row</td></tr>';
$(newRow).insertBefore('table > tbody > tr:first');
updateIndex;
});
});
調用函數..'u pdateIndex()' –
@RajaprabhuAravindasamy感謝您的評論,我已將它更改爲'updateIndex()',但是這會返回以下錯誤:無法獲取未定義或空引用的屬性項。這是因爲'updateIndex()'需要兩個參數,'(e,ui)'? –