DataGrid属性中有一个用于过滤源始数据的方法,该方法的使用:
1、注意:这个函数必须返回包含'total'和'rows'属性的标准数据对象。easyui的API中明确注明。
示例:
$('#dg_fq').datagrid({
fit : true,
method : 'post',
url : rootPath + 'overdue_query_list.xhtml',
rownumbers : true,
toolbar :'#toolbar_fq', //设置toolbar
singleSelect : true,
nowrap : true,
striped : true,
remoteSort :false,
pagination : true,
pageSize : 15,
pageList : [5,10,15,20,25,30,35,40,45,50],
frozenColumns:[[{field:'id', checkbox:true}]],
columns : columns_fq,
loadFilter : function(data){
//过滤数据
var value={
total:data.total,
rows:[]
};
var x=0;
for (var i = 0; i < data.rows.length; i++) {
if(data.rows[i].tranModel.productType=="02"){
value.rows[x++]=data.rows[i];
}
}
return value;
},
onLoadSuccess : function() {
//在数据加载成功的时候触发
$('#dg_fq').datagrid('clearChecked');
$("#dg_fq").datagrid('tooltip'); //数据过长会浮动显示
},
onClickRow : function(index, row){
var apartDay=row.apartDay;
if(row.tranModel.loanPrincipal!=null){
$("#fm #loanprincipal").text(row.tranModel.loanPrincipal+"元");
}
}
});
中,用
loadFilter : function(data){
//过滤数据
var value={
total:data.total,
rows:[]
};
var x=0;
for (var i = 0; i < data.rows.length; i++) {
if(data.rows[i].tranModel.productType=="02"){
value.rows[x++]=data.rows[i];
}
}
return value;
}
成功的进行了对数据过滤,不满足的数据不展示在datagrid中。
json数据格式如下:
{
"total": 1,
"rows": [
{
"tid": "30",
"name": "小四",
"no": "500240100008085090",
"surplusamount": null,
"maxamount": null,
"creditpoint": null,
"phone": "12300000000",
"tranModel": {
"id": 30,
"userId": 1,
"state": 8,
"errorMsg": null,
"loanInitRate": 0.0005,
"loanRealRate": 0.0005,
"loanInitManageRate": 0.001333,
"loanRealManageRate": 0.001333,
"loanReceipts": "tjk012016011500006",
"transReceipts": "075598712016000000027-013",
"loanPrincipal": 1000,
"loanDate": 1452443160000,
"planRepayDays": 7,
"planRepayDate": 1452960000000,
"planRepayInterest": 54.99,
"planRepayAccrual": 15,
"planRepayFee": 39.99,
"planRepayAmount": 1054.99,
"fixThirdpartyCost": 2,
"loanSysCardID": 1,
"loanUserCardID": 1,
"reviewDate": 1452788760000,
"reviewSysUser": 9999,
"transferDate": 1452443160000,
"transferSysUser": 9999,
"leftAmount": 1000,
"leftRepayInterest": 0,
"realRepayDate": null,
"realRepayDays": 9,
"realRepayInterest": null,
"realRepayAccrual": null,
"realRepayFee": null,
"realRepayOverDueAccrual": null,
"realRepayOverDueFee": null,
"realRepayAmount": null,
"realRepayPrincipal": null,
"realThirdpartyCost": null,
"repaySysCardID": null,
"failCause": null,
"contractSignature": "0",
"contractState": 1,
"oldState": null,
"repayReceipts": null,
"discountAmount": 0,
"discountType": null,
"couponNo": null,
"comments": null,
"version": 1,
"productType": "01",
"overdueRate": 0.0002,
"overdueManageRate": 0.0005332,
"phasedNums": null,
"repayTimes": 0,
"isLoanNormCheck": 1,
"illegalUseAdd": null,
"overDueAdd": null,
"iVersion": 2,
"thirdpartyRepayFeeRate": null
},
"bankCard": "中国银行 尾号0000",
"bankCode": 3,
"accountNo": "6212480000000000",
"msgCount": null,
"apartDay": null,
"loanPoundage": 54.99,
"overdueAmount": 5.13,
"overdueDay": 3,
"bankName": "中国银行",
"prmList": null,
"reviewSysUserStr": null,
"apartDayFQ": null,
"currentTime": null
}
]
}
此处逻辑很简单,只过滤需要的productType为02的数据,所以以上数据不会再datagrid中被显示出来,理解后,可根据自己的业务需求,进行复杂的过滤逻辑实现。