Tablesorter 可编辑,如何为新添加的行启用编辑
Tablesorter editable, howto enable edit for a newly added row
我将 tablesorter 与 editable 和过滤器插件一起使用。
此外,我使用传呼机(不认为它相关)。
现在我的页面上有一个按钮,可以打开一个表单来向 table 添加新行。但是我首先使用 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 调用的 return 上,我实际上将行添加到 html table,如下所示:
$('.tablesorter tbody').append(toHtml(record));
$('.tablesorter').trigger('update', true);
toHtml(record) 函数为具有唯一 ID 的行创建 html 代码(已检查)。
该行已正确添加到 table,过滤和排序有效,但是...该行不是 editable,其他行仍然是 editable。
如何使我新添加的行编辑table?
我的解决方案是将可编辑列定义为数组而不是文本:
editable_columns: [0, 1, 2, 3, 4]
我将 tablesorter 与 editable 和过滤器插件一起使用。 此外,我使用传呼机(不认为它相关)。
现在我的页面上有一个按钮,可以打开一个表单来向 table 添加新行。但是我首先使用 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 调用的 return 上,我实际上将行添加到 html table,如下所示:
$('.tablesorter tbody').append(toHtml(record));
$('.tablesorter').trigger('update', true);
toHtml(record) 函数为具有唯一 ID 的行创建 html 代码(已检查)。
该行已正确添加到 table,过滤和排序有效,但是...该行不是 editable,其他行仍然是 editable。
如何使我新添加的行编辑table?
我的解决方案是将可编辑列定义为数组而不是文本: editable_columns: [0, 1, 2, 3, 4]