We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Enable to reset the datasource with anothers datas

Hello, 

I have this PivotView congured like that : 

                    pivotGridObj = new ej.pivotview.PivotView({
                        dataSource: {
                            enableSorting: true,
                            columns: [],
                            rows: [],
                            valueSortSettings: {
                                headerDelimiter: ' - '
                            },
                            data: ej.data.DataUtil.parse.isJson($scope.data),
                            expandAll: false,
                            formatSettings: [],
                            values: [],
                            filters: [],
                        },
                        showFieldList: true,
                        displayOption: {
                            view: 'Chart'
                        },
                        chartSettings: {
                            chartSeries: {
                                type: 'Column'
                            },

                        },
                        //showToolbar: true,
                        allowCalculatedField: true,
                        //toolbar: ['Chart'],
                        width: '99%',
                        height: '100%',
                    });


                    pivotGridObj.appendTo('#' + id);

How Can I reset the datasource from this specific PivotGridObj with completely another data structure ?

When I try to reset this PivotGrid with this code :

                    pivotGridObj = document.getElementById(id).ej2_instances[0];
                    pivotGridObj.dataSource = {
                        enableSorting: true,
                        columns: [],
                        rows: [],
                        valueSortSettings: {
                            headerDelimiter: ' - '
                        },
                        data: ej.data.DataUtil.parse.isJson($scope.data),
                        expandAll: false,
                        formatSettings: [],
                        values: [],
                        filters: [],
                    };

It doesnt work at all. I just retrieve my precedent field list with my actual new properties.


Here it is Before with initial data :


And After i Try to reset the datasource with other datas :
the data structure is not the same, ie : in new datas I don't have 'OptionPossible' property...



Coud you please help me ?

Thx

4 Replies

SR Sabaridass Ramamoorthy Syncfusion Team May 3, 2019 07:10 AM UTC

Hi Foulont, 

You can refresh “fieldlist” by using below code snippet when refreshing the data. 

Code Snippet: 
refreshBtn.element.onclick = function () { 
    pivotGridObj.engineModule.fieldList = {}; 
} 
 

Please let us know if you need further assistance on this. 

Regards, 
Sabaridass R 



FG Foulont Gaetan May 3, 2019 07:27 AM UTC

Hello, 

Thanks for your replay but it doesnt work if I change completly the structure of the json when I refresh.

See the stackblitz below:





FG Foulont Gaetan replied to Sabaridass Ramamoorthy May 3, 2019 07:27 AM UTC

Hi Foulont, 

You can refresh “fieldlist” by using below code snippet when refreshing the data. 

Code Snippet: 
refreshBtn.element.onclick = function () { 
    pivotGridObj.engineModule.fieldList = {}; 
} 
 

Please let us know if you need further assistance on this. 

Regards, 
Sabaridass R 


Hello, 

Thanks for your replay but it doesnt work if I change completly the structure of the json when I refresh.

See the stackblitz below:




SR Sabaridass Ramamoorthy Syncfusion Team May 3, 2019 12:45 PM UTC

Hi Foulont, 

Thanks for the reply. 

You need to remove row, column and value fields which are not included in the data. You can remove fields by using following code snippet. 
Code Snippet: 
   var pivotGridObj = new ej.pivotview.PivotView({ 
        enginePopulating: function(args) { 
          var report = {}; 
          report[0] = args.dataSource.rows; 
          report[1] = args.dataSource.columns; 
          report[2] = args.dataSource.values; 
          report[3] = args.dataSource.filters; 
          var pos = 0; 
          while (pos < 4) { 
            if (report[pos]) { 
              for (var cnt = 0; cnt < report[pos].length; cnt++) { 
                if (Object.keys(args.dataSource.data[0]).indexOf(report[pos][cnt].name) == -1) { 
                  report[pos].splice(cnt, 1); 
                  cnt--; 
                } 
              } 
            } 
            pos++; 
          } 
        } 
    }); 
    pivotGridObj.appendTo('#PivotView'); 
 
 

Please let us know if you need further assistance on this. 

Regards, 
Sabaridass R 


Loader.
Live Chat Icon For mobile
Up arrow icon