jqgrid filterToolbar not working
Well i am banging my head against the wall with this one because i have used jqgrid in many apps and similar code is working in every other case but this! Here is the code...
var pfct = $("#pfc_table");
pfct.jqGrid({
url: 'costs',
datatype: 'json',
'postData': JSON.stringify(getConds()),
mtype: 'POST',
colNames:['Id','Name','Formula','Conditions'],
colModel :[
{name:'id', inde开发者_运维百科x:'id', width:40, search:true},
{name:'name', index:'name', width:130, search:true},
{
name:'formula', index:'formula',width:310, search:true,
formatter : function(value, options, rData){
return value.substring(value.indexOf('=')+1);
}
},
{name:'conditionstr', index:'conditionstr', width:160,search:true}
],
jsonReader: {
repeatitems:false,
root: function (r) { return r.data.rows; },
page: function (r) { return r.data.currpage; },
total: function (r) { return r.data.totalpages; },
records: function (r) { return r.data.totalrecords; }
},
gridComplete: function() {
},
gridview: true,
height: 'auto',
autowidth: true,
pager: '#pfc_pager',
rowNum:25,
viewrecords: true,
loadonce: true,
ignoreCase: true,
multiselect: false,
pagination: true
});
pfct.navGrid('#pfc_pager',{edit:false,add:false,del:false,search:false,refresh:false});
pfct.jqGrid('filterToolbar',{stringResult: true,searchOnEnter: false});
The json data i am sending have a few extra properties that are not defined in the colmodel but this has never been a problem in the past. Local sorting and paging works fine, but filtering does not! For the record this is what the data looks like:
{"data":{"totalpages":1,"currpage":1,"totalrecords":10,"rows":[{"name":"Test","id":18195,"level":0,"currency":"EUR","default":true,"formula":"f_18195()=110","ownerId":1,"categoryName":"Test cat","parentId":0,"rebate":0,"portDues":true,"modified":1310036286000,"conditionstr":"Condition 1, Condition 2"}],"userdata":null},"status":true,"responseError":null}
Your original grid has one problem. You use custom formatter for the 'formula' column:
formatter : function(value, options, rData){
return value.substring(value.indexOf('=')+1);
}
so the data "f_18195()=110"
will be displayed as "100"
. The way works good in case of datatype: 'json'
without loadonce: true
, but works wrong in case of loadonce: true
. The problem is that the data saved locally for the formula
column will be "f_18195()=110"
and not "100"
. So during filtering of the data one have to type "f" or "f_18195()=1" instead of "1" to filter the data:
You can fix the problem if you would use jsonmap
as function:
jsonmap: function (obj) {
var f = obj.formula;
return f.substring(f.indexOf('=')+1);
}
instead of usage of usage of custom formatter for the 'formula' column. In the case the value "100" will be saved locally and the filtering of data works as expected:
See the corresponding demo here.
精彩评论