网格没有刷新,添加对话框提交后没有关闭,为什么?

时间:2018-01-16 20:52:46

标签: javascript jquery free-jqgrid

我正在努力尝试:

  • 从远程
  • 刷新网格内容
  • 关闭添加对话框

点击“提交”按钮后,由于对话框之后仍然打开,并且网格没有重新加载内容,因此它不适用于我。这就是我的代码的样子:

$(function () {
    "use strict";

    var manage_drugs_list_grid = $("#manage_drugs_list");
    manage_drugs_list_grid.jqGrid({
        colNames: ["Actions", "Drug Name", "Date Created"],
        colModel: [
            {name: "act", template: "actions", width: 50, align: "left"},
            {name: "DrugName", search: true, stype: "text", editable: true},
            {
                name: "DateCreated",
                search: true,
                editable: false,
                formatter: "date",
                sorttype: "date",
                formatoptions: {
                    newformat: "n/j/Y g:i:s A"
                },
                width: 50
            }
        ],
        cmTemplate: {
            width: 300,
            autoResizable: true
        },
        iconSet: "fontAwesome",
        rowNum: 25,
        guiStyle: "bootstrap",
        autoResizing: {
            compact: true,
            resetWidthOrg: true
        },
        rowList: [25, 50, 100, "10000:All"],
        viewrecords: true,
        autoencode: true,
        sortable: true,
        pager: true,
        toppager: true,
        hoverrows: true,
        multiselect: true,
        multiPageSelection: true,
        rownumbers: true,
        sortname: "Id",
        sortorder: "desc",
        loadonce: true,
        autowidth: true,
        autoresizeOnLoad: true,
        forceClientSorting: true,
        ignoreCase: true,
        prmNames: {id: "Id"},
        jsonReader: {id: "Id"},
        editurl: "/ajax/drugs/upsert",
        url: '/ajax/drugs/get',
        datatype: "json",
        formDeleting: {
            url: '/ajax/drugs/delete',
            delicon: [true, "left", "fa-scissors"],
            cancelicon: [true, "left", "fa-times"],
            width: 320,
            caption: 'Delete form',
            msg: 'Are you sure you want to delete this drug?',
            beforeShowForm: function ($form) {
                var rowids = $form.find("#DelData>td").data("rowids");

                if (rowids.length > 1) {
                    $form.find("td.delmsg").html('Are you sure you want to delete all the selected drugs?');
                }
            },
            afterComplete: function (response, postdata, formid) {
                if (response.responseText === "true") {
                    toastr["success"]("The form was deleted successfully.", "Information");
                } else {
                    toastr["error"]("Something went wrong, the form could not be deleted.", "Error");
                }
            }
        },
        navOptions: {
            edit: false,
            add: true,
            search: false,
            refresh: true
        },
        loadComplete: function () {
            var $self = $(this), p = $self.jqGrid("getGridParam");

            if (p.datatype === "json") {
                // recreate the toolbar because we use generateValue: true option in the toolbar
                $self.jqGrid("destroyFilterToolbar").jqGrid("filterToolbar");
            }
        }
    }).jqGrid('navGrid', {
        addtext: "Add",
        reloadAfterSubmit: true,
        closeAfterAdd: true,
        closeAfterEdit: true,
        reloadGridOptions: {fromServer: true}
    });
});

我找到了这个Oleg answer,但不适合我,很确定我在错误的地方使用了错误的语法或错误的事件。

更新

在再次尝试谷歌后,我发现了这个问题/答案:Close add dialog after submit这使我转到jQgrid Wiki并查看navGrid中的可用选项,然后转到{ {3}}页面。阅读完这些文档后,我将代码更改为:

.jqGrid('navGrid', {
    addtext: "Add",
    reloadGridOptions: {fromServer: true}
}, {
    addCaption: "Add new drug",
    closeAfterAdd: true,
    clearAfterAdd: true,
    closeOnEscape: true
}) 

然而,这些变化并没有使我的问题消失。标题不会被覆盖,在添加新记录后对话框没有关闭,按 ESC 键不会进行任何更改,这意味着对话框保留在页面上等等。

更新#1:

在阅读jQgrid源代码并寻找一些线索后,我现在通过在网格定义中添加以下内容来进行第3次尝试:

formEditing: {
    caption: 'Add new form',
    closeAfterEdit: true,
    closeOnEscape: true
},

仍然无法正常工作。

想法?

0 个答案:

没有答案