jqGrid更新下拉选项基于第一个选定的下拉菜单编辑模式

时间:2018-01-28 09:41:48

标签: javascript c# jquery jqgrid

我有一个jqGrid加载正常,下拉加载也很好,但我不确定要根据第一个下拉列表的onchange事件更新(加载)第二个下拉列表。

这是我的网格。如您所见,我加载国家但现在我想根据所选国家/地区加载可用货币。

$("#jqgrid").jqGrid
        ({
            url: '@Url.Action("GetSupplierData", "Maintenance")',
            datatype: 'json',
            mtype: 'Get',
            //table header name
            colNames: [
                'Id', 'Code', 'Name', 'Account Number', 'Contact Person', 'Contact Number',
                'Email', 'Address', 'Country', 'Currency', 'InsertUserId',
                'InsertDateTime', 'InsertUserName', 'UpdateUserId', 'UpdateDateTime', 'UpdateUserName'
            ],
            //colModel takes the data from controller and binds to grid
            colModel: [
                {
                    key: true,
                    hidden: true,
                    name: 'id',
                    index: 'id',
                    editable: true
                }, {
                    key: false,
                    name: 'code',
                    index: 'code',
                    editable: true
                }, {
                    key: false,
                    name: 'name',
                    index: 'name',
                    editable: true
                }, {
                    key: false,
                    name: 'accountnumber',
                    index: 'accountnumber',
                    editable: true
                }, {
                    key: false,
                    name: 'contactperson',
                    index: 'contactperson',
                    editable: true
                }, {
                    key: false,
                    name: 'contactnumber',
                    index: 'contactnumber',
                    editable: true
                }, {
                    key: false,
                    name: 'email',
                    index: 'email',
                    editable: true
                }, {
                    key: false,
                    name: 'address',
                    index: 'address',
                    editable: true
                }, {
                    key: false,
                    name: 'countryId',
                    index: 'countryId',
                    editable: true,
                    edittype: 'select',
                    editoptions: {
                        dataInit: function(element) {
                            $.ajax({
                                url: '@Url.Action("GetCountries", "Maintenance")',
                                dataType: 'json',
                                type: 'POST',
                                success: function(response) {
                                    var array = response;
                                    if (array != null) {
                                        var i;
                                        for (i in array) {
                                            if (array.hasOwnProperty(i)) {
                                                if (ctyId == array[i].id) {
                                                    $(element).append("<option value=" + array[i].id +" selected>" + array[i].name +"</option>");
                                                } else {
                                                    $(element).append("<option value=" + array[i].id + ">" + array[i].name + "</option>");
                                                }
                                            }
                                        }
                                    }
                                }
                            });
                        },
                        dataEvents:
                            {
                                type: 'change',
                                fn: function (e) {
                                }
                            }
                    },
                    editrules: { required: true, integer: true }
                }, {
                    key: false,
                    name: 'currencyId',
                    index: 'currencyId',
                    editable: true
                }, {
                    key: false,
                    hidden: true,
                    name: 'insertUserId',
                    index: 'insertUserId',
                    editable: true
                }, {
                    key: false,
                    hidden: true,
                    name: 'insertDateTime',
                    index: 'insertDateTime',
                    editable: true
                }, {
                    key: false,
                    hidden: true,
                    name: 'insertUserName',
                    index: 'insertUserName',
                    editable: true
                }, {
                    key: false,
                    hidden: true,
                    name: 'updateUserId',
                    index: 'updateUserId',
                    editable: true
                }, {
                    key: false,
                    hidden: true,
                    name: 'updateDateTime',
                    index: 'updateDateTime',
                    editable: true
                }, {
                    key: false,
                    hidden: true,
                    name: 'updateUserName',
                    index: 'updateUserName',
                    editable: true
                }
            ],
            rowNum: 10,
            rowList: [10, 20, 30, 40],
            height: '100%',
            caption: 'Suppliers',
            emptyrecords: 'No records to display',
            jsonReader:
            {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: false,
                Id: "0"
            },
            pager: '#pjqgrid',
            sortname: 'id',
            toolbarfilter: true,
            viewrecords: true,
            sortorder: "asc",
            autowidth: true,
            multiselect: false,
            onSelectRow: function(id) {
                var selRowId = $("#jqgrid").jqGrid('getGridParam', 'selrow');
                ctyId = $("#jqgrid").jqGrid('getCell', selRowId, 'currencyId');
            }
            //pager-you have to choose here what icons should appear at the bottom
            //like edit,create,delete icons
        }).navGrid('#pjqgrid',
            {
                edit: true,
                add: false,
                del: true,
                search: true,
                refresh: true
            },
            {
                // edit options
                zIndex: 1000,
                url: '@Url.Action("EditSupplier", "Maintenance")',
                dataType: "html",
                closeOnEscape: true,
                closeAfterEdit: true,
                recreateForm: true,
                afterComplete: function(response) {
                    $('#alerts').html(response.responseText);
                }
            },
            {
                // add options

            },
            {
                // delete options
                zIndex: 1000,
                url: '@Url.Action("DeleteSupplier", "Maintenance")',
                type: "POST",
                closeOnEscape: true,
                closeAfterDelete: true,
                recreateForm: true,
                msg: "Are you sure you want to delete this?",
                afterComplete: function(response) {
                    $('#alerts').html(response.responseText);
                }
            });

1 个答案:

答案 0 :(得分:0)

jqGrid example的这个Guriddo会指出你正确的方向。

相关问题