jqgrid treegrid 重新加載本地數據


首先jqgrid treegrid  加載本地數據的方法如下:

var $gridList = $('#list');
        var grid = $gridList.jqGrid({
            datatype : 'jsonstring',
            datastr : data,
            colModel : [],
            viewrecords : true,
            //gridview:true,
            treeGrid : true,
            treedatatype : "local",
            treeGridModel : "adjacency",
            ExpandColumn : 'name',
            height : $(window).height() - 240,
            autowidth : '100%',
            width : $gridList.parent().width() - 1,
            jsonReader : {
                repeatitems : false,
                root : function(obj) {
                    return obj;
                },
                page : function(obj) {
                    return 1;
                },
                total : function(obj) {
                    return 1;
                },
                records : function(obj) {
                    return obj.length;
                }
            }
        });

其中,不同於treegrid加載遠程返回對象的是,需要設置datatype : 'jsonstring',數據也要賦值在datastr屬性上

  datatype : 'jsonstring',
  datastr : data,
  treedatatype : "local",
 

加載之后的效果:

 

 但是在第一次加載之后,還會有后續的查詢操作,一般的從服務器返回json形式的數據的時候,代碼如下:
$("#list").jqGrid('setGridParam', {
            postData : postData,
            page : 1
        }).trigger('reloadGrid');

網上搜索的treegrid的重新加載的方法,如下:

$jqGrid.jqGrid('setGridParam',{ 
                    url:path+"/admin/demo/getLogsGridJson.do", 
                    postData:{'aaa':111,'bbb':222}, //
                    page:1,
                    treedatatype : 'json'
}).trigger("reloadGrid");

上面這段代碼,在以treegrid形式重新加載本地數據的情況下,並不起作用,(我沒有調試重新加載遠程數據的情況)

在stackoverflow上搜索到一篇文章,代碼如下:

$("#list").setGridParam({
    datatype: "jsonstring",
    datastr: init()
}).trigger("reloadGrid", [{page: 1}]);

 

依然,上面這段代碼,在以treegrid形式重新加載本地數據的情況下,並不起作用,(我沒有調試重新加載遠程數據的情況)
后來實在沒有辦法,在這個上面耽誤的時間已經太多了,終極解決方式:
$("#container").empty();
            $("#container").append('<table id="list"></table>');

清空,重加元素,然后再重新綁定

 

參考網址:

https://stackoverflow.com/questions/17260450/jqgrid-reload-datatype-local-for-each-request

https://blog.csdn.net/qq_29542611/article/details/74979762

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM