1

jqwidget グリッドのセル編集の例 (jqxGrid の左メニューで [編集]/[編集] を開く) では、クライアントでデータが生成されます。ドロップダウンリストを asp .net MVC3 プロジェクト内のデータベースにバインドするにはどうすればよいですか?(デモタブの製品列の下にドロップダウンリストが表示されます)

4

2 に答える 2

3

データベースでドロップダウンリストを初期化するときは、それをデータソース (またはデータアダプター) にバインドし、selectedIndex を設定する必要があります。次に、行の更新のために、選択した値を選択したままにする必要があります。

列の定義は次のようになります。

{ 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 });
                      $(document).on('select', editor, function (event) {
                          selectedUrunId = editor.jqxDropDownList('getSelectedIndex');
                      });
                  }
}

変数「selectedUrunId」は、おそらくvar selectedUrunId = -1;jqxgrid の初期化前のように、グローバルに定義する必要があります。次に、updaterow 定義 (ソース定義にあります) で、ドロップダウンの選択された値を使用する必要があります。次のようになります。

if (selectedUrunId != undefined && selectedUrunId != -1) {
                    rowdata.UrunId = selectedUrunId;
                    selectedUrunId = -1;
                }

このシナリオの全体的なシーンは次のとおりです。

        // prepare the data
        var gridSource = {
            datatype: "json",
            datafields: [{ name: 'KargoId' }, { name: 'UrunAdi' }, { name: 'UrunId', type: 'int' }],
            url: 'BindGrid',
            updaterow: function (rowid, rowdata) {
                // synchronize with the server - send update command  
                if (selectedUrunId != undefined && selectedUrunId != -1) {
                    rowdata.UrunId = selectedUrunId;
                    selectedUrunId = -1;
                }                   

                var data = $.param(rowdata);

                $.ajax({
                    dataType: 'json',
                    url: 'UpdateEditGrid',
                    data: data,
                    success: function (data, status, xhr) {
                        gridDataAdapter.dataBind();                            
                    },
                    error: function (xhr, status, error) {
                        alert(JSON.stringify(xhr));
                    }
                });
            }
        };

        var gridDataAdapter = new $.jqx.dataAdapter(gridSource);

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

        var selectedUrunId = -1;
        var dropdownListAdapter = new $.jqx.dataAdapter(dropdownSource);

        // initialize jqxGrid
        $("#jqxgrid").jqxGrid(
        {
            width: 670,
            source: gridDataAdapter,
            editable: true,
            theme: theme,
            selectionmode: 'singlecell',
            columns: [
              { text: '#', datafield: 'KargoId', width: 40 },                  
              { 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 });
                      $(document).on('select', editor, function (event) {
                          selectedUrunId = editor.jqxDropDownList('getSelectedIndex');
                      });
                  }
              }]
        });
于 2012-07-12T09:27:46.750 に答える
0

「createeditor」という関数を使用して、内部の DropDownList を初期化できます。

列の定義:

{ text: 'Proyecto', columntype: 'dropdownlist', datafield: 'jobid', width: 10,
                      createeditor: function (row, cellvalue, editor) {
                          editor.jqxDropDownList({ displayMember: 'displaylabel', valueMember: 'catalogvalue', source: dropdownListAdapter });
                      }
}

DropDownList のデータ アダプターは、同様のコードを使用して初期化できます。

source = {
    datatype: "xml",
    datafields: [
    { name: 'CompanyName' },
    { name: 'ContactName' },
    { name: 'ContactTitle' },
    { name: 'City' },
    { name: 'Country' },
    { name: 'Address' }
    ],
    async: false,
    record: 'Table',
    url: 'Default.aspx/GetCustomers',
};
var dropdownListAdapter = new $.jqx.dataAdapter(source,
    {  contentType: 'application/json; charset=utf-8'}
);   
于 2012-07-10T10:10:23.197 に答える