Tablesorter可编辑,如何为新添加的行启用编辑

时间:2015-06-22 13:51:32

标签: jquery ajax tablesorter

我使用带有可编辑和过滤插件的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代码(选中)。

该行已正确添加到表中,过滤和排序有效,但是...行不可编辑,其他行仍可编辑。

如何让我新添加的行可编辑?

1 个答案:

答案 0 :(得分:1)

我的解决方案是将可编辑列定义为数组而不是文本: editable_columns:[0,1,2,3,4]

相关问题