0

我正在尝试将下拉列表(在 jqxgrid 单元格内)绑定到数据库,但是下拉列表的更改事件(以及同时行更新功能)多次工作,然后网格被锁定。下拉列表绑定到具有数据字段“UrunAdi”的列。而且,它是一个 asp .net mvc3 项目。有什么建议吗?

代码是:

var gridSource = {
            datatype: "json",
            datafields: [{ name: 'KargoId' }, { name: 'Ad' }, { name: 'Soyad' }, { name: 'UrunAdi' }, { name: 'UrunId', type: 'int' }, { name: 'Uygunluk', type: 'boolean' },
                         { name: 'YuklenmeTarihi', type: 'date' }, { name: 'Adet' }, { name: 'Fiyat'}],
            url: 'BindGrid',
            updaterow: function (rowid, rowdata) {                    
                var data = $.param(rowdata);
                //alert(data);
                $.ajax({
                    dataType: 'json',
                    url: 'UpdateEditGrid',
                    data: data,
                    success: function (data, status, xhr) {
                        // update command is executed.
                    }
                });
            }
        };

        var gridDataAdapter = new $.jqx.dataAdapter(gridSource, {
            downloadComplete: function (data, status, xhr) { },
            loadComplete: function (data) { $("#jqxgrid").jqxGrid('hidecolumn', 'UrunId'); },
            loadError: function (xhr, status, error) { alert(JSON.stringify(xhr)); }
        });

        var dropdownSource = {
            datatype: "json",
            datafields: [{ name: 'UrunId' }, { name: 'UrunAdi'}],
            url: 'BindDropdown'
        };

        var dropdownListAdapter = new $.jqx.dataAdapter(dropdownSource, { autoBind: true, async: false });

        // initialize jqxGrid
        $("#jqxgrid").jqxGrid(
        {
            width: 670,
            source: gridDataAdapter,
            editable: true,
            theme: theme,
            selectionmode: 'singlecell',
            columns: [
              { text: '#', datafield: 'KargoId', width: 40 },
              { text: 'Ad', columntype: 'textbox', datafield: 'Ad', width: 90 },
              { text: 'Soyad', datafield: 'Soyad', columntype: 'textbox', width: 90 },
              { text: 'Urun', columntype: 'dropdownlist', datafield: 'UrunAdi', width: 177,
                  initeditor: function (row, cellvalue, editor) {
                      var urunId = $('#jqxgrid').jqxGrid('getcellvalue', row, "UrunId");
                      editor.jqxDropDownList({ displayMember: 'UrunAdi', source: dropdownListAdapter, selectedIndex: urunId });
                      editor.bind('change', function (event) {
                          var selectedUrunId = editor.jqxDropDownList('getSelectedIndex');
                          $('#jqxgrid').jqxGrid('setcellvalue', row, "UrunId", selectedUrunId);
                      });
                  }
              },
              { text: 'UrunId', datafield: 'UrunId' },...
4

1 回答 1

1

我将 UrunAdi(下拉列表列)的列定义更改为:

 { text: 'Urun', columntype: 'dropdownlist', datafield: 'UrunAdi', width: 177,
                  initeditor: function (row, cellvalue, editor) {
                      var urunId = $('#jqxgrid').jqxGrid('getcellvalue', row, "UrunId");
                      editor.jqxDropDownList({ displayMember: 'UrunAdi', source: dropdownListAdapter, selectedIndex: urunId });
                      editor.bind('change', function (event) {
                          selectedUrunId = editor.jqxDropDownList('getSelectedIndex');
                      });
                  }
              }

只有一个区别:

删除$('#jqxgrid').jqxGrid('setcellvalue', row, "UrunId", selectedUrunId);我认为“setcellvalue”事件会触发 updaterow。

于 2012-07-11T15:11:29.287 回答