将新按钮动态添加到DataTable jquery中

时间:2016-03-07 13:02:32

标签: javascript jquery datatables

我已经成功实现了创建按钮,它在我的数据表中创建了OK,但我不知道如何在新行中插入按钮。请看图片: enter image description here

注意:我有隐藏的列ID。 这是我的JS:

$('.button14').click(function () {

        $.ajax({
            url: "/AdeccoViews/CreateAdeccoView",
            contentType: 'application/json;',
            data: JSON.stringify({ date: document.getElementById('datepickerCreateModal').value, client: $('#Client :selected').val(), eventType: $('#Event :selected').val() }),
            //data: JSON.stringify({ id: t.row('.selected').data()[0] }),//pravi kod
            type: 'POST',
            success: function (result) {
                if (result.id > 0) {t.row.add([
                            result.id,
                            document.getElementById('datepickerCreateModal').value,
                            $('#Client :selected').text(),
                             $('#Event :selected').text(),
                             result.name,
                             'buttonEdit, buttonDelete'@*,
                             '@Html.Raw(@"<button type=""button"" data-id=""65"" class=""btnEdit"" data-toggle=""modal"" data-target=""#modalFirst"">Edit</button>
                <button type=""button"" data-id=""65"" class=""button13"">Delete</button>")'*@
                ]).draw(false);
                }
                $('#modalCreate').modal('toggle');
                swal("Dodato!", "Novi je dodat!", "success");
            },
            error: function (valid) {
                //window.location.href = "/Views/ERROR";
                swal("Došlo je do greške!", "Molimo vas da pokušate ponovo!", "error");
            }
        });
    });

编辑:success: function (result) { if (result.id > 0) {t.row.add([ result.id, document.getElementById('datepickerCreateModal').value, $('#Client :selected').text(), $('#Event :selected').text(), result.name, t.row.add(result) ]).draw(false); } $('#modalCreate').modal('toggle'); swal("Dodato!", "Novi je dodat!", "success"); }

0 个答案:

没有答案