第一种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",{
label : "当前接入量",name : "BytesOutCount",{
label : "历史接入量",name : "BytesOutPerDay",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",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",width:"20px",rowObject){
var type = "";
if(0 == cellvalue){
type = "一般公告";
}else if(1 == cellvalue){
type = "重要公告";
}
return type;
}
},{name:"content",index:"content",sortable:true},{name:"createTime",index:"create_time",{name:"status",index:"4",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");
}
}
},multiselect : true,// 每页显示记录数
rowList : [10,// 用于改变显示行数的下拉列表框的元素数组
pager : "#systemNoticePage",});
//jqGrid自适应宽度
$(window).resize(function(){
$("#systemNoticeTabel").jqGrid({autowidth:false}).setGridWidth($(window).width());
});
原文链接:https://www.f2er.com/ajax/160631.html