Results 1 to 6 of 6

Thread: PIvot Grid Config Persist

  1. #1
    Sencha User
    Join Date
    Dec 2015
    Posts
    117
    Answers
    12

    Default Answered: PIvot Grid Config Persist

    Hello,

    I am planning to provide the user the pivot configurator, so they can pivot any way they want.
    I would like to be able to save/load those configurations to/from the database, how do we do that?

    Thank you,

  2. You can get the pivot configuration from the plugin:

    var cfg = pivot.getPlugin('configurator').getConfiguration();

    Clone that object and from that you can get aggregate, topAxis, leftAxis objects, but you need to clean them up, delete some properties, functions, arrays, IDs, etc. you end up with the configuration properties.
    You should also, grab and save the filters and sorters, and any pivot settings.

    Then you can load a saved configuration using:

    pivot.reconfigurePivot(cfg);

    Then apply the filters and sorters, and any pivot settings like totals position, etc.

  3. #2
    Sencha Premium User varsos's Avatar
    Join Date
    Feb 2008
    Location
    Long Island, NY
    Posts
    367
    Answers
    6

    Default

    You can get the pivot configuration from the plugin:

    var cfg = pivot.getPlugin('configurator').getConfiguration();

    Clone that object and from that you can get aggregate, topAxis, leftAxis objects, but you need to clean them up, delete some properties, functions, arrays, IDs, etc. you end up with the configuration properties.
    You should also, grab and save the filters and sorters, and any pivot settings.

    Then you can load a saved configuration using:

    pivot.reconfigurePivot(cfg);

    Then apply the filters and sorters, and any pivot settings like totals position, etc.
    varsos

  4. #3
    Sencha User
    Join Date
    Oct 2015
    Posts
    52
    Answers
    1

    Default

    Quote Originally Posted by herme063 View Post
    Hello,

    I am planning to provide the user the pivot configurator, so they can pivot any way they want.
    I would like to be able to save/load those configurations to/from the database, how do we do that?

    Thank you,
    do you have any example on this topic? i want do something just like you but i don't know how to save config to db,JSON.stringify can't convert ext object to string.

  5. #4
    Sencha User
    Join Date
    Oct 2015
    Posts
    52
    Answers
    1

    Default

    Quote Originally Posted by varsos View Post
    You can get the pivot configuration from the plugin:

    var cfg = pivot.getPlugin('configurator').getConfiguration();

    Clone that object and from that you can get aggregate, topAxis, leftAxis objects, but you need to clean them up, delete some properties, functions, arrays, IDs, etc. you end up with the configuration properties.
    You should also, grab and save the filters and sorters, and any pivot settings.

    Then you can load a saved configuration using:

    pivot.reconfigurePivot(cfg);

    Then apply the filters and sorters, and any pivot settings like totals position, etc.

    do you have any example on this topic? i want do something just like you but i don't know how to save config to db,JSON.stringify can't convert ext object to string.

  6. #5
    Sencha User
    Join Date
    Dec 2015
    Posts
    117
    Answers
    12

    Default

    I end up doing as follow to retrieve the config directly from the pivot(me):


    Code:
        
        /**
         * This method retrieves the pivot view config.
         */
        getPivotConfig: function () {
            var me = this,
                matrix = me.getMatrix(),
                matrixDimensionFields = 'id,header,dataIndex,sortIndex,width,flex,align,sortable,direction,caseSensitiveSort,filter,formatter,exportStyle,blankText,showZeroAsBlank,aggregator,grouper',
                matrixDimensionFilterFields = 'dimensionId,topType,topOrder,topSort,isTopFilter,type,operator,value,caseSensitive',
                getMatrixConfig = function (i) {
                    var config = Ext.copy({}, i.initialConfig, matrixDimensionFields);
                    if (config.filter) {
                        config.filter = Ext.copy({}, config.filter, matrixDimensionFilterFields);
                    }
    
    
                    return config;
                };
            return {
                leftAxis: Ext.Array.map(matrix.leftAxis.dimensions.items, getMatrixConfig),
                topAxis: Ext.Array.map(matrix.topAxis.dimensions.items, getMatrixConfig),
                aggregate: Ext.Array.map(matrix.aggregate.items, getMatrixConfig)
            };
        }

    The gist of it is to cleanup the configuration items (and filters). JSON.stringify should work fine with the resulting object.

  7. #6
    Sencha User
    Join Date
    Oct 2015
    Posts
    52
    Answers
    1

    Default

    Quote Originally Posted by herme063 View Post
    I end up doing as follow to retrieve the config directly from the pivot(me):


    Code:
        
        /**
         * This method retrieves the pivot view config.
         */
        getPivotConfig: function () {
            var me = this,
                matrix = me.getMatrix(),
                matrixDimensionFields = 'id,header,dataIndex,sortIndex,width,flex,align,sortable,direction,caseSensitiveSort,filter,formatter,exportStyle,blankText,showZeroAsBlank,aggregator,grouper',
                matrixDimensionFilterFields = 'dimensionId,topType,topOrder,topSort,isTopFilter,type,operator,value,caseSensitive',
                getMatrixConfig = function (i) {
                    var config = Ext.copy({}, i.initialConfig, matrixDimensionFields);
                    if (config.filter) {
                        config.filter = Ext.copy({}, config.filter, matrixDimensionFilterFields);
                    }
    
    
                    return config;
                };
            return {
                leftAxis: Ext.Array.map(matrix.leftAxis.dimensions.items, getMatrixConfig),
                topAxis: Ext.Array.map(matrix.topAxis.dimensions.items, getMatrixConfig),
                aggregate: Ext.Array.map(matrix.aggregate.items, getMatrixConfig)
            };
        }

    The gist of it is to cleanup the configuration items (and filters). JSON.stringify should work fine with the resulting object.
    thanks for your help, how can i reset the config back to view?(i try to use reconfigurePivot but not working)

Similar Threads

  1. Model Field Persist config not working for me?!
    By parky128 in forum Sencha Touch 2.x: Discussion
    Replies: 3
    Last Post: 8 Oct 2013, 12:44 PM
  2. Pivot Grid how to config width a columns?
    By HEILEENDURLEY in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 25 Jul 2013, 8:47 AM
  3. Persist grid columns' sequence
    By samjoshi263 in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 5 Jul 2009, 5:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •