EasyUI Forum

General Category => Bug Report => Topic started by: jpierce on October 08, 2013, 02:08:22 PM



Title: calling datagrid refreshRow on expanded row causes row to disappear
Post by: jpierce on October 08, 2013, 02:08:22 PM
When refreshRow is called on an exanded master-detail grid row, the row content disappears. To reproduce, go to http://www.jeasyui.com/demo/main/index.php?plugin=DataGrid&theme=default&dir=ltr&pitem= and click on the Master Detail grid.  Expand the first item, then enter the following in the javascript console:
Code:
$('#dg').datagrid('refreshRow', 0);


Title: Re: calling datagrid refreshRow on expanded row causes row to disappear
Post by: stworthy on October 09, 2013, 01:13:18 AM
Because the detail contents are loaded via AJAX, calling 'refreshRow' method can not restore its original contents. To solve this issue, the user must load the detail content manually after calling 'refreshRow' method.
Code:
$('#dg').datagrid('refreshRow',0);
$('#ddv-0').panel({...});


Title: Re: calling datagrid refreshRow on expanded row causes row to disappear
Post by: jpierce on October 09, 2013, 07:55:00 AM
Thanks.  But upon refreshRow, couldn't you have all expanded rows call onExpandRow again?


Title: Re: calling datagrid refreshRow on expanded row causes row to disappear
Post by: stworthy on October 09, 2013, 05:24:15 PM
The 'refreshRow' method only do update the row content including the detail native content. It can't trigger 'onExpandRow' event. If you want, try the code below to expand a row manually, it will auto expand a row and update its ajax content.
Code:
$('#dg').datagrid('refreshRow',0).datagrid('collapseRow',0).datagrid('expandRow',0);


Title: Re: calling datagrid refreshRow on expanded row causes row to disappear
Post by: jpierce on October 10, 2013, 08:11:23 AM
Well, you'd certainly know more about it than me, so what I'm doing may have some bad side-effects.  But this seems effective:
Code:
var detailview2 = $.extend({}, detailview, {
    updateRow:function (target, rowIndex, row) {
        var dc = $.data(target, 'datagrid').dc;
        var opts = $.data(target, 'datagrid').options;
        var cls = $(target).datagrid('getExpander', rowIndex).attr('class');
        $.fn.datagrid.defaults.view.updateRow.call(this, target, rowIndex, row);
        $(target).datagrid('getExpander', rowIndex).attr('class', cls);

        // update the detail content
        if (this.canUpdateDetail) {
            var row = $(target).datagrid('getRows')[rowIndex];
            var detail = $(target).datagrid('getRowDetail', rowIndex);
            detail.html(opts.detailFormatter.call(target, rowIndex, row));

            if (opts.onExpandRow) {
                opts.onExpandRow.call(this, rowIndex, row);
            }
        }
    }
});

Is there something wrong with this that I'm not noticing?


Title: Re: calling datagrid refreshRow on expanded row causes row to disappear
Post by: stworthy on October 10, 2013, 06:02:13 PM
Please try this.
Code:
var detailview2 = $.extend({}, detailview, {
updateRow:function (target, rowIndex, row) {
var opts = $(target).datagrid('options');
detailview.updateRow.call(this, target, rowIndex, row);
var expander = $(target).datagrid('getExpander', rowIndex);
if (this.canUpdateDetail && expander.hasClass('datagrid-row-collapse')) {
if (opts.onExpandRow) {
var row = $(target).datagrid('getRows')[rowIndex];
opts.onExpandRow.call(this, rowIndex, row);
}
}
}
});


Title: Re: calling datagrid refreshRow on expanded row causes row to disappear
Post by: jpierce on October 11, 2013, 07:10:24 AM
Thanks.  That's basically the same code as mine, just with some of the redundant stuff taken out, right?

Is there any reason this shouldn't be part of the core?  I'm still not sure if I understand why you earler said it couldn't/shouldn't be.