EasyUI Forum

General Category => Bug Report => Topic started by: kiddkyd on March 08, 2015, 10:20:05 PM



Title: formatter in datagrid has bug in 1.4.2
Post by: kiddkyd on March 08, 2015, 10:20:05 PM
my data is only 2 rows,
我的数据只有2行,

but it will call the formatter function 3 times.
但是它会触发3次formatter的方法

In first time,the 'value ,row' is undefined. :-\
第一次执行的时候,参数的'value,row'都是undefined


Title: Re: formatter in datagrid has bug in 1.4.2
Post by: stworthy on March 09, 2015, 12:55:44 AM
That's no matter. The 'formatter' function is called by $.fn.datagrid.defaults.view.renderRow. At the first time, the datagrid will call 'renderRow' with empty row data to render an empty row.
If you really want to prevent the 'formatter' function from calling more than once, please override the 'renderEmptyRow' function of view to solve this issue.
Code:
(function($){
var renderEmptyRow = $.fn.datagrid.defaults.view.renderEmptyRow;
$.extend($.fn.datagrid.defaults.view, {
renderEmptyRow:function(target){
var fields = $(target).datagrid('getColumnFields');
for(var i=0; i<fields.length; i++){
var col = $(target).datagrid('getColumnOption', fields[i]);
col.formatter1 = col.formatter;
col.styler1 = col.styler;
col.formatter = col.styler = undefined;
}
renderEmptyRow.call(this, target);
for(var i=0; i<fields.length; i++){
var col = $(target).datagrid('getColumnOption', fields[i]);
col.formatter = col.formatter1;
col.styler = col.styler1;
col.formatter1 = col.styler1 = undefined;
}
}
})
})(jQuery);


Title: Re: formatter in datagrid has bug in 1.4.2
Post by: zhcnlei on March 09, 2015, 01:47:15 AM
Should be judged before use.


Title: Re: formatter in datagrid has bug in 1.4.2
Post by: kiddkyd on March 09, 2015, 02:55:21 AM
That's no matter. The 'formatter' function is called by $.fn.datagrid.defaults.view.renderRow. At the first time, the datagrid will call 'renderRow' with empty row data to render an empty row.
If you really want to prevent the 'formatter' function from calling more than once, please override the 'renderEmptyRow' function of view to solve this issue.
Code:
(function($){
var renderEmptyRow = $.fn.datagrid.defaults.view.renderEmptyRow;
$.extend($.fn.datagrid.defaults.view, {
renderEmptyRow:function(target){
var fields = $(target).datagrid('getColumnFields');
for(var i=0; i<fields.length; i++){
var col = $(target).datagrid('getColumnOption', fields[i]);
col.formatter1 = col.formatter;
col.styler1 = col.styler;
col.formatter = col.styler = undefined;
}
renderEmptyRow.call(this, target);
for(var i=0; i<fields.length; i++){
var col = $(target).datagrid('getColumnOption', fields[i]);
col.formatter = col.formatter1;
col.styler = col.styler1;
col.formatter1 = col.styler1 = undefined;
}
}
})
})(jQuery);

There is no such problem in 1.4.1.
Only the 1.4.2 need to write like this?


Title: Re: formatter in datagrid has bug in 1.4.2
Post by: jpierce on May 19, 2015, 07:31:42 AM
We just upgraded to 1.4.2 and I ran into this feature as well. What's the purpose of renderEmptyRow and will overriding it thwart it? Will there be any bad side-effects. I guess I'm just not understanding this bit of code change since it causes invalid data to be fed to the formatter function.