Retrieve dynamic data for Pivot in Devexpress AngularJS

I am currently working on an AngularJS web app where I am implementing a Pivot using devexpress, specifically utilizing the Field Chooser. You can find the example code here:

In the provided example, static data is used. However, I need to fetch data dynamically from the server. To achieve this, I have written the following code:

$scope.testData = null;
$scope.pivotGridDataSource = new DevExpress.data.PivotGridDataSource({
   fields: [{
     caption: "Name",
     dataField: "fullName",
     area: "row"
    }, {
     caption: "Country",
     dataField: "country",
     area: "column"
  }, {
    caption: "Count",
    dataField: "countOne",
    dataType: "number",
    summaryType: "sum",
    area: "data"
  }],
     store: $scope.testData
  });

  $scope.pivotGridOptions = {
     allowSortingBySummary: true,
     allowSorting: true,
     allowFiltering: true,
     showBorders: true,
     dataSource: $scope.pivotGridDataSource,
     fieldChooser: {
        enabled: false
     }
   },

   $scope.fieldChooserOptions = {
      dataSource: $scope.pivotGridDataSource,
         texts: {
            allFields: "All",
            columnFields: "Columns",
            dataFields: "Data",
            rowFields: "Rows",
            filterFields: "Filter"
           },
          width: 400,
          height: 400,
          bindingOptions: {
             layout: "layout"
          }
      };

  // Function to retrieve data
  $scope.getTestData = () => {
     // Call the server and save the data
     ........
      $scope.testData = result;
  }

However, after fetching the data, the table remains empty with the message "No data". I have also tried calling:

$scope.pivotGridDataSource.load();
$scope.pivotGridDataSource.reload();

after retrieving the data from the server, but the issue persists.

Answer №1

The issue lies within your store, so here is a solution you can implement

var dataStore = new DevExpress.data.CustomStore({
                load: function (loadOptions) {
                    var d = $.Deferred();
                    $.ajax({
                        url: UrlApi,
                        method: "GET",
                    }).done(function (result) {
                        d.resolve(result, {
                        });
                    });
                    return d.promise();
                },
                key: "Id",
            });


$scope.pivotGridDataSource = new DevExpress.data.PivotGridDataSource({
   .......
     store: dataStore
  });

Take a look at this code snippet which uses jQuery, although AngularJS functions similarly

var dataStore = new DevExpress.data.CustomStore({
                load: function (loadOptions) {
                    var d = $.Deferred();
                    $.ajax({
                        url: UrlApi,
                        method: "GET",
                    }).done(function (result) {
                        d.resolve(result, {
                        });
                    });
                    return d.promise();
                },
                key: "Id",
            });
        $("#pvtSales").dxPivotGrid({
            showBorders: true,
            "export": {
                enabled: true,
                fileName: "Sales"
            },
            dataSource: {
                fields: [{
                    caption: "Fecha",
                    dataField: "maeFecha",
                    width: 350,
                    area: "row"
                }, {
                    caption: "Nombre",
                    dataField: "maeNombre",
                    dataType: "number",
                    summaryType: "count",
                    area: "data"
                }, {
                    dataField: "maeGestion",
                    width: 350,
                    area: "column"
                }],
                store: dataStore
            }
        });

Observe the outcomes by clicking on this link

https://i.sstatic.net/5BEvb.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

My API is feeding data to the Material UI CardMedia image

Has anyone encountered a similar error while using the CardMedia API provided by Material-UI? I am currently utilizing the Card & CardMedia components from material-ui to display data fetched from an api. However, I am facing difficulty in displaying ...

What is the best way to position a div to float or hover from the bottom after it has been

I am working on creating a menu where clicking it will reveal a submenu at the bottom, but I'm encountering an issue. Currently, in my code, the submenu is appearing from right to left before moving down. Here is my code: <meta name="viewport" co ...

exploring the capabilities of sockets in PHP, reminiscent of the functionality found in Node.js

I recently downloaded and tried out a basic chat app with Node.js: https://github.com/socketio/chat-example The app is functioning properly. The server-side code is quite straightforward: var app = require('express')(); var http = require(&ap ...

Struggling to find a way to showcase API data on a HTML site

Is there a way to dynamically show the live prices of crypto currencies on my website? I wrote a script that successfully displays the current price, but I'm struggling with implementing auto-refresh using setInterval. Here's the code I have so f ...

How can I add a string before a hashtag(#) in AngularJS URLs?

Can we add a prefix to the # symbol in angular.js URLs? For instance: let's say we have a site: http://example.com/ then when I click on the CSharp page, it redirects to http://example.com/#/csharp when I click on the AngularJS page, it redi ...

Utilizing Vue and Vuex to execute Axios operations within a store module

Currently, I am developing an application in Vue that utilizes Vuex for state management. For CRUD operations on the data, I have implemented Axios. The issue arises when, for example... I make a POST request to my MongoDB database through an Express ...

Displaying an HTML file in a Node and Express application using JavaScript File handling

Starting my first Node, Express & Angular project has been a bit tricky due to issues with the asset pipeline. I'm not entirely sure if it's related to my folder structure, which I tried setting up based on online tutorials but am open to suggest ...

so many alerts to choose from aside from jsx/react

After some consideration, I believed I had devised an effective way to notify users when the array is empty and there's nothing to display. However, upon implementation, I realized my technique only works onFocus or page reload because I placed the fu ...

Discover the package.json file within an Angular application

Currently, I have my app running with ng serve. I'm curious if there is a method to access the package.json file within my app. My initial thought was to move package.json to the directory ./dist and retrieve it from there. However, this does not see ...

Using axios with async/await to handle unresolved promises in Javascript

I'm facing a challenge with a piece of code I've been working on. Despite my efforts to find a solution online, I haven't had any success so far. Here is the code snippet in question: const fetchSidebarData = async () => { let da ...

Error: The 'in' operator cannot be utilized to search for 'length' in the Kendo UI framework

I am encountering an error while using Angular 1.4, jQuery 1.11.3, and the latest Kendo UI. I'm wondering if this issue is a known bug to Telerik. The only Kendo controls present on the page are kendo-multi-select and kendo-date-picker. TypeError: C ...

If the progress bar in AngularJS reaches 100%, the "active" class will be automatically removed

How can I remove the bootstrap 'active' class from the progress bar once it reaches 100% to stop the stripes from moving? I tried this, but it's not working: <div class="progress progress-striped active" style="margin-bottom: 0;" n ...

Are there alternative methods for inserting data into an array in JavaScript?

I'm having trouble with my code that is supposed to push data to an array variable, but instead I'm getting a blank array. Can someone help me figure out what I'm doing wrong? let users = [] // Here is where I'm looping through an aja ...

The function cannot be called on a type that does not have a callable signature. The specified type, 'number | Dispatch<SetStateAction<number>>', does not have any compatible call signatures

Currently, I am working on setting up state to be passed through context in React using hooks. However, when I attempt to use the dispatched state updater function, an error is thrown: Cannot invoke an expression whose type lacks a call signature. Type &a ...

Ensure that the loader remains visible until all data has been successfully retrieved from the AngularJS service

Currently, I am facing an issue with the implementation of angularjs ui-router for state transitions along with a loader assigned to each view. The problem arises when moving from one state to another and the loader disappears before all the content from t ...

What is the best way to control the class name of elements using jQuery in an MVC4 application?

Among the <li> elements, one of them contains the class "current". Determining which <li> is the current one. View below: @{ int k = 10; //the value changes with each request } <ul class="car"> @foreach (var item in modelCoun ...

Observables waiting inside one another

I've encountered an issue where I need to return an observable and at times, within that observable, I require a value from another observable. To simplify my problem, let's consider the following code snippet: public dummyStream(): Observabl ...

Is my approach to CSV parsing correct if I am receiving the error "Unable to assign property 'processing' to undefined"?

In our database, we store words along with their categories. I have a new requirement to enable the word administrator to upload multiple words at once using a CSV file. Currently, our system only allows for single-word additions at a time. My solution was ...

Chaining fade in and slide effects on a div element

I am attempting to display a <div> named settings when a button is clicked. The intention is for it to fade in and then slide towards the right side of the screen, originating from the left side. Progress so far: The HTML <div id="settings" ng- ...

Sending emails with SMTP in JavaScript using the mailto form

I'm facing a challenge with my form. I am looking for a way to have the Send-email button trigger mailto without opening an email client, instead automatically sending via JavaScript (smtp). I'm not sure if this is achievable or if I'm askin ...