JQGrid:编辑后如何刷新下拉列表? [英] JQGrid: How can I refresh a dropdown after edit?

查看:14
本文介绍了JQGrid:编辑后如何刷新下拉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用 JQGrid 加载一些联系人数据,当我编辑/添加条目时,我从数据库中选择联系人的姓名,然后更新/添加联系人.

In my application, I use JQGrid for loading some contacts data, and when I edit/add an entry I select the contact's name from database and then update/add contact.

我的问题是,当我点击提交按钮时,我想刷新下拉列表,并且已经输入的数据从下拉列表中消失.

My problem is that, when I click the submit button I want to refresh the dropdown and the data that has been already entered to dispaear from dropdown list.

我的代码:

对于 colModel:

for colModel:

{ name: 'OwnerEmail', index: 'OwnerEmail', width: 200, align: "center", sortable: true, sorttype: 'text', editable: true, edittype: 'select', editrules: { required: true }, editoptions: { value: ownersList} },

我在选择行上填充下拉菜单(当我选择一行时,下拉菜单将被刷新)

I populate the dropdown on select row (that when I select a row, the dropdown will be refreshed)

onSelectRow: function (id) {
                var advOwners = $.ajax({
                    type: 'POST',
                    data: {},
                    url: 'MyWebService.asmx/GetOwners',
                    async: false,
                    error: function () {
                        alert('An error has occured retrieving Owners!');
                    }
                }).responseXML;

                var aux = advOwners.getElementsByTagName("string");
                ownersList = "";
                for (var i = 0; i < aux.length; i++) {
                    ownersList += aux[i].childNodes[0].nodeValue + ':' + aux[i].childNodes[0].nodeValue + '; ';
                }
                ownersList = ownersList.substring(0, ownersList.length - 2);

                jQuery("#GridView").setColProp('OwnerEmail', { editoptions: { value: ownersList} });
             }

但是当我再次进入编辑/添加表单时,下拉菜单没有刷新,它有首先加载的项目.

But when I enter the edit/add form again, the dropdown it's not refreshed, it has the items that has been loaded in the first place.

有什么帮助吗?

谢谢,杰夫

推荐答案

我认为如果你使用 editoptions 而不是使用 value 属性.在这种情况下,您不需要在 onSelectRow 内使用同步 Ajax 调用来手动获取选择数据.如果需要数据,相应的调用将为您执行 jqGrid.

I think it will be better if you would use dataUrl property of the editoptions instead of usage value property. In the case you will don't need to use synchronous Ajax call inside of onSelectRow to get the select data manually. If the data will be needed the corresponding call will do jqGrid for you.

dataUrl 中的 URL 应返回

发送“验证码”获取 | 15天全站免登陆