nnajm / orb

Pivot table javascript library
https://nnajm.github.io/orb/
MIT License
558 stars 172 forks source link

How to get the config (made by the user) and refresh (with stored config) via javascript? #41

Open ograndebe opened 8 years ago

ograndebe commented 8 years ago

I tried to store a config object and change the configuration via Javascript. But, after first config refresh, the pivot table not work properly.

There's an example:

var fngetConfig = function(myPivot) {
    console.log(myPivot.pivot);
    var config = myPivot.pivot.pgrid.config;
    var myConfig = {
        dataHeadersLocation: config.dataHeadersLocation,
        theme: config.theme.current(),
        toolbar: {
            visible: true
        },
        grandTotal: {
            rowsvisible: true,
            columnsvisible: true
        },
        subTotal: {
            visible: true,
            collapsed: true
        },
        fields: config.allFields,
        width: config.width,
        height: config.height,
        rows: [],
        columns: [],
        data: [],
        preFilters : {}
    };

    $.each(config.rowFields, function(idx, vField) {
        myConfig.rows.push(vField);
    });
    $.each(config.columnFields, function(idx, vField) {
        myConfig.columns.push(vField);
    });
    $.each(config.dataFields, function(idx, vField) {
        myConfig.data.push(vField);
    });

    return myConfig;
};

var fnRefreshPivot = function (storedConfig, myPivot, myDiv) {
        $("#"+myDiv).empty();
    var divEl = document.getElementById(myDiv);
    myPivot = new orb.pgridwidget(storedConfig);
    myPivot.render(divEl);
};

![Uploading problema_orb.PNG…]() this problem occurs when I drag the fields after the first refresh

ograndebe commented 8 years ago

problema_orb

EduFrazao commented 8 years ago

Save and restore the current state is a great feature. I think that state changes can be notified by an event or requested via API. So we can restore it anytime later. Its not supported by default?

ghost commented 7 years ago

Basically you have to save all the fields and applied filters manually. 1) Use these functions to retrieve fields and their positions:

myPivot.pgrid.config.dataFields myPivot.pgrid.config.columnFields myPivot.pgrid.config.rowFields

2) Get filter for each field using:

myPivot.pgrid.getFieldFilter()

To restore fields and filters use you have to know current positions of each field (repeat previous steps to get current pivot state) then you should:

3) Restore fields positions with

myPivot.moveField()

4) Restore filters with

myPivot.applyFilter()