【发布时间】:2014-08-30 09:41:07
【问题描述】:
我已阅读旧线程 (here) 关于删除行后更新表的内容。一般的方法是使用.trigger('update').trigger("appendCache").trigger("applyWidgets")。但这不起作用,因为行将返回排序。在示例中,它仅添加了editable 小部件。谁能告诉我为什么触发器不起作用?
var options = {
theme: 'default',
widgets: ['editable'],
widgetOptions : {
editable_columns : [0,1,2],
editable_enterToAccept : true,
editable_autoAccept : true,
editable_autoResort : false,
editable_validate : null,
editable_noEdit : 'no-edit',
editable_editComplete : 'editComplete'
}
}
$('.tablesorter2').tablesorter(options).children('tbody').on('editComplete','td', function(event, config){
var $this = $(this),
tr = $this.parent('tr'),
$allRows = config.$tbodies.children('tr'),
tid = tr.data('tid'),
input="",
name = $(this).data('name'),
newContent = $(this).text();
input = '<input value="'+newContent+'" name="'+name+'[]" type="hidden">';
$this.find('.j_input').html(input);
});
$('button').click(function(){
$('input:checked').closest('tr').remove();
$('tablesorter2').trigger('update').trigger("appendCache").trigger("applyWidgets");
});
HTML:
<button>Del</button>
<table class="tablesorter2">
<thead>
<tr data-tid='12'>
<th>Name</th>
<th>Age</th>
<th>Conditions</th>
<th>Notes</th>
<th>Del</th>
</tr>
</thead>
<tbody>
<tr data-tid='13'>
<td><div>Peter</div></td>
<td contenteditable="true" data-name='age'>18<span class='j_input'></span></td>
<td contenteditable="true" data-name='conditions'>Good<span class='j_input'></span></td>
<td contenteditable="true" data-name='notes'>...<span class='j_input'></span></td>
<td><input type='checkbox'/></td>
</tr>
<tr>
<td>Tom</td>
<td data-name='age'>12<span class='j_input'></span></td>
<td contenteditable="true" data-name='conditions'>Good<span class='j_input'></span></td>
<td contenteditable="true" data-name='notes'>On medication<span class='j_input'></span></td>
<td><input type='checkbox'/></td>
</tr>
</tbody></table>
【问题讨论】:
-
表格排序器在加载时“缓存”内容,所以你必须在
ajax调用之后重新绑定tablesort,参见:stackoverflow.com/questions/3210933/…
标签: javascript jquery html tablesorter