EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Juan Antonio Martínez on May 21, 2015, 09:22:57 AM



Title: On-the-fly change datagrid view ¿is it possible? [SOLVED]
Post by: Juan Antonio Martínez on May 21, 2015, 09:22:57 AM
Hi all.

Is it posible to change on-the-fly a datagrid view?. That is:

Code:
function changeView(dg, alternateView) {  
    if (typeof(myConfig.defaultView)==='undefined') myConfig.defaultView=dg.datagrid('opts',view);
    if (needAlternateView()){
        dg.datagrid({view:alternateView});
        dg.datagrid('hideColumn',"columnToHideInAltView");
    } else {
        dg.datagrid({view:myConfig.defaultView});
        dg.datagrid('showColumn',"columnToHideInAltView");
    }
    dg.datagrid('reload');
}

If true, what's the way to initialize new view and reset to default one?
Thanks in advance


Title: Re: On-the-fly change datagrid view ¿is it possible?
Post by: Juan Antonio Martínez on May 21, 2015, 12:51:34 PM
OK. this works for me :-)
Code:
function testAndSetView(dg,alternateView) {
    if (needAlternativeView()){
        dg.datagrid({
            view: alternateView,
            // set additional dg options
            groupField: 'NombreEquipo',
            groupFormatter: formatTeamResults
        });
        // fix column visibility on new view
        dg.datagrid('hideColumn',"Logo");
    } else {
        // set default view
        dg.datagrid({view:$.fn.datagrid.defaults.view});
        // fix column visibility for this view
        dg.datagrid('showColumn',"Logo");
    }
    // finally clear datagrid
    dg.datagrid('loadData', {"total":0,"rows":[]});
    // dg.datagrid('reload');
}

Some issues still persist:
- how can I remove alternateView extra options when switching to default?
- when setting new view, datagrid is automagically rendered with old and useless data... any way to avoid this behaviour