jqGrid:如何在启用表单编辑的情况下在每行中添加编辑和删除按钮?

贾希鲁尔

我有一个如下图所示的网格:

用于在每行中添加编辑和删除按钮的图像,如黑框所示

目前,我在页脚中有添加,编辑,删除按钮。我需要在每行中都有“编辑”和“删除”按钮。当我单击每一行中的“编辑”按钮时,它将显示编辑表单,而当单击“提交”时,它将数据保存到数据库中。

我的代码如下所示:

    $(document).ready(function () {
        //jQuery.extend(jQuery.jgrid.defaults, { altRows:true });
        $("#list_records").jqGrid({
            url: 'ajaxELearningFetchTableData.php?table=GET_TRAINING_TYPE',
            //url: 'server.php',
            editurl: 'ajaxELearningSaveTrainingType.php',
            datatype: "json",
            colNames: ["TRAINING TYPE ID", "TRAINING TYPE NAME", "REMARKS"],
            colModel: [
                {
                    label: 'TRAINING TYPE ID',
                    name: 'TRAINING_TYPE_ID',
                    index: 'TRAINING_TYPE_ID',
                    editable: true,
                    sortable: true,
                    sorttype: "text",
                    editoptions: {readonly: "readonly"},
                    width: 40
                },
                {
                    label: 'TRAINING TYPE NAME',
                    name: 'TRAINING_TYPE_NAME',
                    index: 'TRAINING_TYPE_NAME',
                    width: 120,
                    editable: true, // must set editable to true if you want to make the field editable
                    editoptions: {size: 50, maxlength: 80},
                    editrules: {required: true, maxlength: 80},
                    sortable: true,
                    sorttype: "text",
                    // set options related to the layout of the Edit and Add Forms
                    formoptions: {
                        colpos: 1, // the position of the column
                        rowpos: 2, // the position of the row
                        label: "Training Type Name:", // the label to show for each input control  
                        elmsuffix: "(*)"

                    }
                },
                {
                    label: 'REMARKS',
                    name: 'REMARKS',
                    width: 140,
                    editable: true,
                    edittype: 'textarea',
                    editoptions: {rows: 3, cols: 45},
                    formoptions: {
                        colpos: 1,
                        rowpos: 3
                    }
                }
            ],
            loadonce: true,
            viewrecords: true,
            altRows: true,
//            width: auto,
//            height: auto,
            width: 1000,
            height: 300,
            rowNum: 10,
            rowList: [10, 20, 30],
            caption: "Training Type Information",
            sortname: 'TRAINING_TYPE_ID',
            sortorder: "asc",
            emptyrecords: "No Records to Display.",

            //footerrow: true,
            pager: "#perpage"
        });

        $('#list_records').navGrid('#perpage',
                // the buttons to appear on the toolbar of the grid
                        {edit: true, add: true, del: true, search: true, refresh: true, view: false, position: "left", cloneToTop: false},
                // options for the Edit Dialog
                        {
                            height: 'auto',
                            width: 620,
                            editCaption: "Edit Training Type",
                            url: 'ajaxSaveTrainingType.php',
                            recreateForm: true,
                            closeAfterEdit: true,
                            afterComplete: function (response) {
                                alert(response.responseText);
                            },

//                            afterShowForm: function(form) {
//                                form.closest('div.ui-jqdialog').center();
//                            },
                            afterSubmit: function () {
                                $(this).jqGrid("setGridParam", {datatype: 'json'});
                                return [true];
                                //location.reload(true);
                            }
                        },
                // options for the Add Dialog
                        {
                            height: 'auto',
                            width: 620,
                            addCaption: "Add Training Type",
                            url: 'ajaxSaveTrainingType.php',
                            closeAfterAdd: true,
                            recreateForm: true,
                            afterComplete: function (response) {
                                alert(response.responseText);
                            },
//                            afterShowForm: function(form) {
//                                form.closest('div.ui-jqdialog').center();
//                            },
//                           
                            afterSubmit: function () {
                                $(this).jqGrid("setGridParam", {datatype: 'json'});
                                return [true];
                                //location.reload(true);
                            }
                        },
                // options for the Delete Dailog
                        {
                            height: 'auto',
                            width: 620,
                            addCaption: "Delete Training Type",
                            url: 'ajaxSaveTrainingType.php',
                            closeAfterAdd: true,
                            recreateForm: true,
                            //rp_ge, postdata
                            onclickSubmit: function () {

                                var sel_id = $('#list_records').jqGrid('getGridParam', 'selrow');
                                var trainingTypeId = $('#list_records').jqGrid('getCell', sel_id, 'TRAINING_TYPE_ID');
                                return {tTypeId: trainingTypeId};


                            },
                            afterComplete: function (response) {
                                alert(response.responseText);
                            },
//                            afterShowForm: function(form) {
//                                form.closest('div.ui-jqdialog').center();
//                            },
                            afterSubmit: function () {
                                $(this).jqGrid("setGridParam", {datatype: 'json'});
                                return [true];
                                //location.reload(true);
                            }
                        });
            });

任何帮助都将受到欢迎。

谢谢。

奥列格

您可以添加formatter: "actions"formatoptions: { editformbutton: true }属性一起使用的列如果您使用免费的jqGrid(这是我开发的jqGrid的分支),则可以使用template: "actions"

{ name: "act", template: "actions", formatoptions: { editformbutton: true } }

请参见该示例的示例。

如果使用旧的jqGrid(版本<= 4.7),则可以添加具有以下属性的列,例如:

{ name: "act", formatter: "actions", formatoptions: { editformbutton: true },
    width: 54, align: "center", fixed: true, hidedlg: true, resizable: false,
    sortable: false, search: false, editable: false, viewable: false }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在启用鼠标的情况下在nano编辑器中复制和粘贴?

如何在Django管理中添加编辑和删除按钮

如何在没有jQuery的情况下在Javascript中添加和删除类

TortoiseGit如何在不影响在线存储库的情况下在本地编辑或删除某些文件

如何在不编辑关系模型的情况下在Entity Framework C#上级联删除

如何在不使用终端的情况下在Mac上编辑/删除.dot_file

如何在不显示标签的情况下在 textarea 中编辑带有标签的 HTML 文档?

Ubuntu 12.04如何在不调用python shell的情况下在IDLE中编辑.py文件?

如何在不使用实体框架的情况下在MVC4中执行编辑功能?

在没有v-if和v-for的情况下在Vue.js的多列中显示(添加,编辑)和删除列表项

如何在不完全用 Python 重写的情况下添加、删除和编辑函数内部的某些行?

禁用jqgrid的编辑(添加,编辑和删除)按钮,而不是隐藏(默认行为)

如何在php中添加编辑按钮

如何在jqGrid的编辑表单中填写文本字段?

如何在免费jqgrid中的表单和行编辑中使用本机日期选择器

如何在不触发 NavigationLink 事件的情况下在列表中添加可点击的按钮?

如何在不重建的情况下在CKEditor中添加或删除插件?

如何在没有任何加载项的情况下在Outlook 2010中编辑电子邮件的HTML源代码?

如何在没有按钮的情况下在android studio中来回淡入和淡出

如何在MVC的jqGrid中添加日期选择器和内联编辑?

添加编辑按钮和删除按钮

默认情况下,需要启用xeditable表单的“编辑”模式

在没有打开编辑器的情况下在文件中添加/编辑行文本(Linux命令)

如何在不损害其功能的情况下在表单数组中添加无效的表单控件

如何在不编辑XAML的情况下向设计器中的网格单元添加控件?

如何在不执行单击事件的情况下在另一个编辑文本中显示一个编辑文本值

如何在表单编辑中的jqgrid中选择编辑类型来验证/发布col

如何在不更改日期的情况下在Seaborn热图上编辑日期时间格式?

WordPress:如何在编辑表单中添加图片上传按钮?