【发布时间】:2015-06-23 19:30:23
【问题描述】:
我使用带有可编辑和过滤插件的tablesorter。 此外,我使用寻呼机(不认为它相关)。
现在我的页面上有一个按钮,可以打开一个表单来向表中添加新行。但是我首先使用 ajax 调用更新数据库,如下所示:
function ajaxUpdateDb(action, record) {
var postdata = JSON.stringify(
{
"Table": $(".tablesorter").attr("id"),
"Action": action,
"Record": record
});
try {
$.ajax({
type: "POST",
url: "../ajax/UpdateData.ashx",
cache: false,
data: postdata,
dataType: "json",
success: getSuccess,
error: getFail,
async: true
});
} catch (e) {
displayMessage(e.message, "alert alert-danger");
}
function getSuccess(data) {
$(".tablesorter").trigger('cancel');
if (data && data.Success) {
record.ID = data.Id;
displayMessage(data.Message, "label label-success");
updateTable(action, record);
} else if (data) {
displayMessage(data.Message, "alert alert-danger");
} else {
displayMessage("operation failed, unknwon error", "alert alert-danger");
}
};
function getFail(jqXhr) {
document.write(jqXhr.responseText);
};
}
然后,在返回 ajax 调用时,我实际上将行添加到 html 表中,如下所示:
$('.tablesorter tbody').append(toHtml(record));
$('.tablesorter').trigger('update', true);
toHtml(record) 函数为具有唯一 id 的行创建 html 代码(检查)。
该行已正确添加到表中,过滤和排序有效,但是...该行不可编辑,其他行仍可编辑。
如何使我新添加的行可编辑?
【问题讨论】:
-
它适用于我:jsfiddle.net/xxmha2Ly/8
-
我稍微改变了你的例子,现在它重现了我遇到的问题。我更改了这一行:editable_columns: "0-4", jsfiddle.net/s36go2m1
标签: jquery ajax tablesorter