0

サーバーから動的な列データと列名をロードし、サーバー側のページネーションを使用するために、これを初めて試みています。

問題は、jqgrid AJAX 呼び出し (2 つ目) で datatype : 'local' を使用すると、データが表示され、サーバー側のページネーションが無効になることです。しかし、AJAX 呼び出しで datatype : 'json' を使用すると、データが表示されません。

動的な列バインディング、クライアント側の並べ替え、サーバー側のページネーションを実現するためのシンプルで明確なソリューションを手に入れるのを手伝ってください。

$(document).ready(function() {
                    $.ajax({
                                type : "POST",
                                url : contextPath + "/getEntities",
                                dataType : "json",
                                success : function(result) {
                                    var colD = result.response,
                                    colM = result.colModList,
                                    colN = result.colNames;

                                    $("#list").jqGrid({
                                        url : contextPath + "/getEntities",
                                        datatype : 'json',
                                        mtype : 'POST',

                                        data : colD,
                                        colNames : colN,
                                        colModel : colM,
                                        pager : '#pager',
                                        rowNum : 10,
                                        rowList : [ 10, 20, 30 ],
                                        sortname : 'column1',
                                        sortorder : 'asc',
                                        viewrecords : true,
                                        gridview : true,
                                        caption : 'My first grid',
                                    });

                                },
                                loadComplete : function() {
                                    $("#list").jqGrid('setGridParam',{datatype:'json'});
                                },

                                error : function(x, e) {
                                    alert(x.readyState + " " + x.status
                                            + " " + e.msg);
                                }
                            });
                });

datatype : 'local' が設定されている場合 (2 番目の AJAX 呼び出し) にデータを表示できるため、サーバーから受信した JSON データに問題はありません。誰かが実用的な例を提供してくれれば、それは大きな助けになるでしょう。

もう 1 つの質問は、グリッドをリロードする理由とその方法です。リロード コードを配置する場所。私はこの部分を取得していません。

どんな助けでも大歓迎です。

更新: 回答が投稿されました。サーバー側のページネーションを使用して動的な列を実装するのに最適です。

4

1 に答える 1

0

作業コード:

$(document).ready(function() {
$.ajax({
        type : "GET",
        url : contextPath + "/getEntities",
        dataType : "json",
        success : function(result) {
            var colM = result.colModList,
            colN = result.colNames;

            $("#list").jqGrid({
                url : contextPath + "/getEntities",
                datatype : 'json',
                mtype : 'GET',
                jsonReader : {
                    root : "response",
                    page : "page",
                    total : "total",
                    records : "records",
                    repeatitems : false,
                    id : "column1"
                },
                colNames : colN,
                colModel : colM,
                pager : '#pager',
                rowNum : 10,
                rowList : [ 10, 20, 30 ],
                sortname : 'column1',
                sortorder : 'asc',
                viewrecords : true,
                gridview : true,
                caption : 'My first grid',
            });

        },
        error : function(x, e) {
            alert(x.readyState + " " + x.status
                    + " " + e.msg);
        }
    });
});
于 2016-08-16T07:05:47.917 に答える