jqgrid ajax加载

来源:互联网 发布:跳蚤街二手市场软件 编辑:程序博客网 时间:2024/06/17 09:08

第一种local

//初始化    var _getData = function(){        _putGrid();        $.ajax({            url :urlPath.kafkaMonitorUrl,            dataType :'json',            //type : "POST",            async : false,            success : function(result) {                if (result["code"] === 200){                    _putGrid(result["Result"]);                }else {                    Messager.alert({                          Msg: result["msg"],                          iconImg: "warning",                          isModal: false                     });                }            }        });    };    //数据装入表格    var _putGrid = function (gridData) {        //加载jar包列表        $("#moduleListTable").jqGrid({            //url : urlPath.kafkaMonitorUrl,            //mtype : "POST",            //datatype : "JSON",            datatype : "local",            data : gridData,            colModel : [ {                label : "Id",                name : "moduleId",                key : true,                hidden : true            }, {                label : "协议类型",                name : "topic",                sortable:true,                align:"center"            },{                label : "当前接入速度",                name : "BytesOutPerSec",                sortable:true,                align:"center"            },{                label : "当前接入量",                name : "BytesOutCount",                sortable:true,                align:"center"            },{                label : "历史接入量",                name : "BytesOutPerDay",                sortable:true,                align:"center"            }            ],            loadonce : false,            forceFit: true,            viewrecords : true,            autowidth : true,            height : false,            rownumbers : true,            multiselect : false,            multiboxonly : true,            rowNum : 10, // 每页显示记录数            rowList : [10, 15, 20 ], // 用于改变显示行数的下拉列表框的元素数组            pager : "#moduleListPage"        });        $("#moduleListTable").jqGrid({autowidth:false}).setGridWidth($(window).width()-300);         };    var _reloadGrid = function(){        $("#moduleListTable").trigger("reloadGrid")    };

第二种直接装

initialization:function () {            $("#systemNoticeTabel").jqGrid({                url : systemNotice.config.systemNoticeInitializationUrl,                 mtype : "POST",                datatype : "JSON",                sortorder: "desc",                colNames : ["公告标题","公告类型","公告内容","发布时间","状态"],                colModel : [                            {name:"title",index:"title",align:"center",width:"30px",sortable:true,                                formatter:function(cellvalue, options, rowObject){                                    var titleType = "";                                    if(1 == rowObject.important){                                        titleType = "<font color=red>★</font>"+cellvalue;                                    }else{                                        titleType = cellvalue;                                        }                                    return titleType;                            }},                            {name:"important",index:"important",align:"center",width:"20px",sortable:true,                                formatter:function(cellvalue, options, rowObject){                                    var type = "";                                    if(0 == cellvalue){                                        type = "一般公告";                                    }else if(1 == cellvalue){                                        type = "重要公告";                                    }                                    return type;                                }                            },                              {name:"content",index:"content",align:"center",width:"30px",sortable:true},                            {name:"createTime",index:"create_time",align:"center",width:"20px",sortable:true},                            {name:"status",index:"4",align:"center",width:"20px",hidden : true,sortable:false}                            ],                /*表格加载完成后执行的函数*/                gridComplete:function(){                    var rowids = $("#systemNoticeTabel").jqGrid('getDataIDs');                    for(var i = 0;i < rowids.length; i++){                    var allrowIds = [];                    allrowIds[i]=rowids[i];                    var allrowDatas = $("#systemNoticeTabel").jqGrid('getRowData',rowids[i]);                    var allrowdatStatus = allrowDatas.status;                    if(allrowdatStatus == "140001001"){                        $("#"+allrowIds[i]).find("td").css("color","red");                        $("#"+allrowIds[i]).find("td").css("font-weight","bold");                    }else{                        $("#"+allrowIds[i]).find("td").css("color","#333");                        $("#"+allrowIds[i]).find("td").css("font-weight","normal");                    }                       }                },                loadonce : false,                forceFit: true,                viewrecords : true,                autowidth : true,                height : false,                rownumbers : true,                multiselect : true,                multiboxonly : true,                rowNum : 10, // 每页显示记录数                rowList : [10, 15, 20 ], // 用于改变显示行数的下拉列表框的元素数组                pager : "#systemNoticePage",                        });            //jqGrid自适应宽度           $(window).resize(function(){                     $("#systemNoticeTabel").jqGrid({autowidth:false}).setGridWidth($(window).width());            }); 
原创粉丝点击