【问题标题】:jqGrid set dataURL Dynamically after Edit Form LoadsjqGrid在编辑表单加载后动态设置dataURL
【发布时间】:2021-08-21 20:23:10
【问题描述】:

我正在使用 jqGrid 4.15.6-pre - 免费 jqGrid:

我的编辑表单中有两个下拉列表。 两者都是使用 onSelectRRow 函数中的 setColProp 从服务器填充的。

如果第一个下拉列表中的值发生更改,我想要重新加载第二个下拉列表。

我需要这样做,而不必关闭编辑表单。

【问题讨论】:

    标签: javascript java jquery free-jqgrid


    【解决方案1】:

    下面的例子使用了 Guriddo jqGrid。您也许可以将其调整为分叉版本 - free-jqgrid。

        $(document).ready(function () {
            $("#jqGrid").jqGrid({
                url: 'data.json',
                editurl: 'clientArray',
                datatype: "json",
                colModel: [
                    {
                        label: 'Customer ID',
                        name: 'CustomerID',
                        width: 75,
                        key: true
                    },
                    {
                        label: 'Company Name',
                        name: 'CompanyName',
                        width: 140,
                        editable: true // must set editable to true if you want to make the field editable
                    },
                    {
                        label : 'Phone',
                        name: 'Phone',
                        width: 100,
                        editable: true
                    },
                    {
                        label: 'Postal Code',
                        name: 'PostalCode',
                        width: 80,
                        editable: true
                    },
                    {
                        name: 'Country',
                        width: 200,
                        editable: true,
                        edittype: "select",
                        editoptions: {
                            value: "USA:USA;UK:UK;Canada:Canada"
                        }
                    },
                    {
                        name: 'City',
                        width: 200,
                        editable: true,
                        edittype: "select",
                        editoptions: {
                            value: "Select a City"
                        }
                    }
                ],
                loadonce: true,
                viewrecorde: true,
                width: 780,
                height: 200,
                rowNum: 10,
                pager: "#jqGridPager"
            });
    
            $('#jqGrid').navGrid('#jqGridPager',
                // the buttons to appear on the toolbar of the grid
                { edit: true, add: false, del: false, search: false, refresh: false, view: false, position: "left", cloneToTop: false },
                // options for the Edit Dialog
                {
                    editCaption: "The Edit Dialog",
                    recreateForm: true,
                    closeAfterEdit: true,
                    viewPagerButtons: false,
                    afterShowForm: populateCities,
                    errorTextFormat: function (data) {
                        return 'Error: ' + data.responseText
                    }
                },
                // options for the Add Dialog
                {
                    closeAfterAdd: true,
                    recreateForm: true,
                    errorTextFormat: function (data) {
                        return 'Error: ' + data.responseText
                    }
                },
                // options for the Delete Dailog
                {
                    errorTextFormat: function (data) {
                        return 'Error: ' + data.responseText
                    }
                });
    
            // This function gets called whenever an edit dialog is opened
            function populateCities() {
                // first of all update the city based on the country               
                updateCityCallBack($("#Country").val(), true);
                // then hook the change event of the country dropdown so that it updates cities all the time
                $("#Country").bind("change", function (e) {
                    updateCityCallBack($("#Country").val(), false);
                });
            }
    
            function updateCityCallBack(country, setselected) {
                var current = $("#jqGrid").jqGrid('getRowData',$("#jqGrid")[0].p.selrow).City;
                $("#City")
                     .html("<option value=''>Loading cities...</option>")
                     .attr("disabled", "disabled");
    
                $.ajax({
                    url: country+".html",
                    type: "GET",
                    success: function (citiesHtml) {
                        $("#City")
                             .removeAttr("disabled")
                             .html(citiesHtml);
                        if(setselected) {
                            $("#City").val( current );
                        }
                    }
                });
            }
    
        });
    

    实时example is here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-21
      相关资源
      最近更新 更多