且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

新的记录添加新行到表的末尾

更新时间:2023-12-03 21:22:16

如果jQuery的解决方案是可以接受的,你可以做到这一点的客户端。下面code可能需要细化,但应该给你一个想法。

If jquery solution is acceptable, you can do it in client side. The below code might need refinement, but should give you an idea.

$("#btnAddConfig").click(function () {
    var template = $("#tblConfig > tbody tr").first().clone();
    var newIndex = $("#hNextConfigIndex").val();
    template.find("input").each(function () {
        var name = $(this).attr("name");
        var id = $(this).attr("id");

        name = name.replace(/\[\d+\]/g, "[" + newIndex + "]");
        id = id.replace(/\_\d+\__/g, "_" + newIndex + "__");

        $(this).attr("name", name);
        $(this).attr("id", id);
        $(this).val(""); //reset to defaults as applicable
    });
    $("#hNextConfigIndex").val(newIndex++);
    $("#tblConfig > tbody").append(template);
});

小提琴

如果你想这样做在服务器端,不重建整个表,但创建一个动作,说 GetEditor 返回一个 TR 与编辑适当的默认值,然后通过 AJAX 提出要求>并追加它使用的jQuery 成功处理程序表。

If you want to do it in server side, don't rebuild the entire table, but create an Action, say GetEditor for returning a tr with appropriate default values for the editor and then request it via ajax and append it to the table using jquery in the success handler.

重建整个表只是增加一个新的记录,每次只是增加了加载时间为记录成长更让用户想知道为什么要花更多的时间每次他增加了一个新的记录时间。

Rebuilding the entire table just for adding a new record every time just adds to the load time as the records grow leaving the user to wonder why it take more and more time each time he adds a new record.