1

'button'の編集タイプを持つ列を持つセル編集可能なjqgridがあります。セルをクリックすると、ボタンが表示されます。ボタンをクリックすると、モーダルダイアログが表示され、ユーザーはグリッドから値を選択できます。これはすべて正常に機能しています。

グリッドから値を選択した後、ユーザーがモーダルダイアログの[OK]ボタンをクリックしたときに、ユーザーが選択した値でセルの値を設定し、セルを保存したいと思います。

セル値を設定して保存する代わりに、セルは空白になります。理由はわかりません。

関連するjqGrid/モーダルダイアログコードは次のとおりです。

// global variables
base.selectedCode = null;
base.liaGridSelectedId = null;
base.liaGridSelectedICol = null;
base.liaGridSelectedIRow = null;

    $("#liaGrid").jqGrid({
        datatype: "local",
        data: base.liaGridData,
        cellEdit: true,
        cellsubmit: 'clientArray',
        height: 140,
        colNames: ['ID', 'Class Code', 'State', 'Location Type'],
        colModel: [
                    { name: 'id', index: 'id', width: 90, sorttype: "int", editable: false, hidden: true },
                    { name: 'ClassCode', index: 'ClassCode', width: 90, sortable: false, editable: true, edittype: "button",
                        editoptions: {
                            dataEvents: [{
                                type: 'click',
                                fn: function (e) {
                                    e.preventDefault();
                                    var rowid = $('#liaGrid').jqGrid('getGridParam', 'selrow');
                                    base.liaGridSelectedId = parseInt(rowid);
                                    $('#class-dialog').dialog('option', { width: 100, height: 200, position: 'center', title: 'Pick a Class' });
                                    $('#class-dialog').dialog('open');

                                    return true;
                                }
                            }]
                        }
                    },
                    { name: 'LocationType', index: 'LocationType', width: 90, sortable: false, editable: true, edittype: "select", editoptions: { value: "0:;1:Rural;2:Suburban;3:Urban"} }
                ],
        caption: "Liability Model",
        beforeEditCell: function (rowid, cellname, value, iRow, iCol) {
            base.liaGridSelectedICol = iCol;
            base.liaGridSelectedIRow = iRow;
        }
    });


    var infoDialog = $('#class-dialog').dialog({
        autoOpen: false,
        modal: true,
        show: 'fade',
        hide: 'fade',
        resizable: true,
        buttons: {
            "Ok": function () {
                if (base.selectedCode != null) {

                    $("#liaGrid").jqGrid('setCell', base.liaGridSelectedId, 'ClassCode', base.selectedCode);

                    $("#liaGrid").jqGrid('saveCell', base.liaGridSelectedIRow, base.liaGridSelectedICol);

                    $(this).dialog("close");
                }
            },
            "Cancel": function () {
                $(this).dialog("close");
            }
        }

    });

上記のように、jqGrid('setCell')とjqGrid('saveCell')を使用して、セルの内容を更新および保存しようとしています。これが成功しない理由がわかりません。

4

1 に答える 1

2

誰かが同様の問題に遭遇した場合に備えて、これを機能させました。afterSaveCellハンドラーをグリッドに追加する必要がありました。

afterSaveCell: function (rowid, name, val, iRow, iCol) {
    if (base.liaGridSelectedICol == 1) {
        $("#liaGrid").jqGrid('setRowData', rowid, { ClassCode: base.selectedCode });
    }
}

参考までに-base.selectedCodeはモーダルで設定されます。

奇妙なことに、これはsetCellメソッドとsaveCellメソッドを呼び出した後にのみ機能しました。セルレベルで設定および保存するためのこれらの失敗した呼び出しがなければ、上記のハンドラーは呼び出されませんでした。

誰かがこの問題を解決するためのより適切なアプローチを持っているなら、私はそれを聞きたいです。

ありがとう

于 2012-05-11T17:42:59.973 に答える