easyui datagrid json擴充套件
阿新 • • 發佈:2019-02-06
如果使用mybatis association,那麼封裝物件後,返回到頁面是json格式的,這種格式
在頁面中顯示出來,跟一下陣列方式有很大區別,不過還好easyui loadFilter支援這種擴充套件
1 easyui json表格
function createDg(){
dgList=$('#dg').datagrid({
method: "post",url:ctx+'/smsHouseholdOrder/find', idField : 'id',singleSelect:true,
fit : true,fitColumns : false,border : false ,striped:true,
pagination:true,rownumbers:true,pageNumber:1,pageSize : 20,pageList : [ 20, 30, 50 ],
columns:[[
{field:'smsHouseholdOrder.id',title:'ID',hidden:true}
,{field:'smsHouseholdOrder.orderId' ,title:'訂單號',sortable:true,width:100,align:'left',halign:'center' }
,{field:'smsOrder.status',title:'狀態',sortable:true,width:80,align:'left',halign:'center',formatter:fmtStatus }
,{field:'smsOrder.appointmentTime' ,title:'預約服務時間',sortable:true,width:120,align:'left',halign:'center',formatter: DzmFrame.EasyUI.fmtDatetime}
,{field:'smsOrder.memberName',title:'會員',sortable:true,width:100,align:'left',halign:'center' }
,{field:'smsOrder.memberPhone',title:'會員手機號',sortable:true,width:100,align:'left',halign:'center' }
,{field:'smsOrder.address',title:'服務地址',sortable:true,width:200,align:'left',halign:'center' }
,{field:'smsHouseholdOrder.times',title:'服務時長',sortable:true,width:100,align:'right',halign:'center' }
,{field:'smsHouseholdOrder.price',title:'單價',sortable:true,width:100,align:'right',halign:'center',formatter:DzmFrame.EasyUI.fmtMoney }
,{field:'smsHouseholdOrder.discount',title:'折扣價',sortable:true,width:100,align:'right',halign:'center',formatter:DzmFrame.EasyUI.fmtMoney }
,{field:'smsHouseholdOrder.amount',title:'金額',sortable:true,width:100,align:'right',halign:'center',formatter:DzmFrame.EasyUI.fmtMoney }
,{field:'smsOrder.orderTime',title:'下單時間',sortable:true,width:120,align:'left',halign:'center',formatter: DzmFrame.EasyUI.fmtDatetime}
]],
sortName:'smsHouseholdOrder.orderId',sortOrder:'asc',
enableHeaderClickMenu: false,
enableHeaderContextMenu: false,
toolbar:'#tb',
loadFilter:function(data){
return DzmFrame.EasyUI.dataGridLoadFilter(data);
}
});
}
2 dataGridLoadFilter
定義filter,解析smsHouseholdOrder.times這種方式的欄位。
var _dataGridLoadFilter = function(data,row,pre){
if(pre)
pre = pre+".";
for (var att in data) {
var r = data[att];
if(typeof(r) == "object"){
if ($.array.isArray(r)){
row[pre+att] = r;
} else{
_dataGridLoadFilter(r,row,pre+att);
}
}else{
row[pre+att] = r;
}
}
}
var dataGridLoadFilter = function(data){
var value = {total:data.total,rows:[]};
if (!$.isEmptyObject(data.rows) && $.isArray(data.rows)){
for (var i=0; i<data.rows.length; i++){
var row = {};
_dataGridLoadFilter(data.rows[i],row,"");
value.rows.push(row);
}
}
return value;
}