1

親jqgridのデータ型がclientSide型の場合、サブグリッドにデータを追加することはできますか?

次を使用して、親jqgridに行を追加できます。

jQuery("#myId").addRowData(0, someRowData);

しかし、サブグリッドにデータを追加する方法がわかりません。何か案は?

4

1 に答える 1

3

jqGridのサブグリッドに実際にデータを追加する方法を特定できませんでしたが、別のグリッド内のグリッドにデータを追加することはできました。

私のマスターグリッドは次のようになります。

$("#" + tblNm).jqGrid({
                datatype: "local",
                colNames: ['id', 'Last Name', 'First Name', 'Address'],
                colModel: [{
                    name: 'id',
                    index: 'id',
                    width: 75,
                    sortable: false
                }, {
                    name: 'lastNm',
                    index: 'lastNm',
                    width: 90,
                    sortable: false
                }, {
                    name: 'firstNm',
                    index: 'firstNm',
                    width: 100,
                    sortable: false
                }, {
                    name: 'address',
                    index: 'address',
                    width: 200,
                    align: "left",
                    sortable: false
                }],
                width: "100%",
                height: "100%",
                caption: "Clients",
                jsonReader: {
                    root: "clients",
                    page: "currpage",
                    total: "totalpages",
                    records: "totalrecords",
                    repeatitems: false,
                    id: "id"
                },
                subGrid: true,
                subGridRowExpanded: function(subgrid_id, row_id){
                    console.debug("SubGrid_ID:  " + subgrid_id +
                    "   / row_id:  " +
                    row_id);
                    var subgrid_table_id, pager_id;
                    subgrid_table_id = "mySubGridName" + row_id;
                    pager_id = "p_" + subgrid_table_id;
                    $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "'></table>");
                    jQuery("#" + subgrid_table_id).jqGrid({
                        datatype: "local",
                        colNames: ['Order Id', 'Item Name', 'Cost'],
                        colModel: [{
                            name: "ordId",
                            index: "ordId",
                            width: 20,
                            key: true
                        }, {
                            name: "itemName",
                            index: "itemName",
                            width: 130
                        }, {
                            name: "cost",
                            index: "cost",
                            width: 200,
                            align: "left"
                        }],
                        rowNum: 20,
                        caption: "Orders",
                        height: '100%',
                        width: '100%',
                        jsonReader: {
                            root: "orders",
                            page: "currpage",
                            total: "totalpages",
                            records: "totalrecords",
                            repeatitems: false,
                            id: "num"
                        }
                    });
                }
            });

次のような操作を行ってマスターグリッドをロードします。

$("#" + tblNm)[0].addJSONData(wrapper);

次に、サブグリッドデータを取得すると、次のようになります。

 // click on the subgrid so that the table is added to the DOM
 // I think there are better ways of doing this... you'll want to look @ the jqGrid documentation
 $("#" + masterTblId + " tr[id='1'] td[role='grid'] a span").click();
 // add the data to the subgrid
 $("#" + subGridId)[0].addJSONData(wrapper);

最も重要な部分は、jqGridのsubgridexpandedプロパティでコードを定義し、サブグリッドを強制的に表示できるようにすることです。

この方法の唯一の問題は、ユーザーがサブグリッド領域をクリックすると切り替えられ、もう一度クリックしても正しく表示されないことです。私はここでそれを修正する方法についてコミュニティに尋ねました:

サブグリッドのキャッシュまたはサブグリッドデータの削除の停止(jqGrid)

于 2010-07-27T22:24:37.423 に答える