Displaying associated foreign-key information in a Kendo grid column

I am facing an issue with my kendo grid that is being controlled by an angular controller:

<div>
    <kendo-grid options="mainGridOptions" k-data-source="gridData">
    </kendo-grid>
</div>

UPDATE The data is loading successfully, however, the grid is not rendering as expected. Additionally, there was a mistake in treating sectors as status.

"use strict";
angular.module("tenderApp")
.controller("tenderCtrl", ["$scope", "adalAuthenticationService", "tenderSvc", "$q", function ($scope, adalService, tenderSvc, $q) {
    $scope.mainGridOptions = null;
    $scope.gridSource = null;
    $scope.statusData = null;

    function loadStatusData() {
        return tenderSvc.getSector()
            .then(function(sector) {
                $scope.sectorData = sector.data.map(function (obj) {
                    return {
                        text: obj.bezeichnung,
                        value: obj.id
                    };
                });
                return $scope.sectorData;
            });
    }

    function loadGridSource(result) {
        return tenderSvc.getItems()
            .then(function (res) {
                $scope.gridSource = res.data;
                return res.data;
            });
    }

    loadStatusData()
        .then(loadGridSource)
        .then(function (res) {
            //both properties are available at this point
            console.log($scope.gridSource);
            console.log($scope.sectorData);
            $scope.gridData = new kendo.data.DataSource({
                transport: {
                    read: function (e) {
                        e.success($scope.gridSource);
                    },
                    //...
                },
                //...
            });
            $scope.mainGridOptions = {
                toolbar: ["excel"],
                dataSource: $scope.gridData,
                columns: [
                    { field: "sektor", title: "Sektor", values: $scope.sectorData },
                    { command: ["edit"], title: "Aktionen", width: "120px" }
                ]
            };

        });
}]);

The main issue I am encountering is that the final call to populate the grid is not functioning correctly. Although the data has been loaded, the grid does not appear on the screen.

Answer №1

Great work! I appreciate the lesson on chaining you've provided. In regards to the issue at hand, it's unnecessary to utilize transport/read. The preferable approach would be to load the data individually and assign it to the grid dataSource as illustrated below. Please refrain from including k-data-source="gridData" in your grid's HTML attribute since you already have grid options defined.

HTML:

<div><kendo-grid options="mainGridOptions" k-data-source="gridData">
</kendo-grid></div>

JS:

"use strict";
angular.module("tenderApp")
.controller("tenderCtrl", ["$scope", "adalAuthenticationService", "tenderSvc", "$q", function ($scope, adalService, tenderSvc, $q) {
    $scope.mainGridOptions = null;
    $scope.gridSource = null;
    $scope.statusData = null;

    $scope.mainGridOptions = {
        dataSource: new kendo.data.DataSource(),
        toolbar: ["excel"],
        columns: [
            { field: "sektor", title: "Sektor", values: $scope.sectorData },
            { command: ["edit"], title: "Aktionen", width: "120px" }
        ]
    };

    function fetchStatusData() {
        return tenderSvc.getSector()
            .then(function(sector) {
                $scope.sectorData = sector.data.map(function (obj) {
                    return {
                        text: obj.bezeichnung,
                        value: obj.id
                    };
                });
                return $scope.sectorData;
            });
    }

    function retrieveGridSource(result) {
        return tenderSvc.getItems()
            .then(function (res) {
                $scope.gridSource = res.data;
                return res.data;
            });
    }

    fetchStatusData()
        .then(retrieveGridSource)
        .then(function (res) {
            $scope.mainGridOptions.dataSource.data($scope.gridSource);
        });
}]); 

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

Accessing values from a JSON object in AngularJS without using a loop based on another field

Is there a way to extract the "value" associated with the "name" in JSON using Angular JS without having to iterate through the array? For instance, if I have an array like the one below with name and value fields, how can I retrieve the value "ABC" based ...

Is there a way to serve server-side rendered content exclusively to search engine crawlers like Google Bot, without SSR for regular users in Next.js?

With a staggering number of users visiting the site every day, we are making strides to enhance our visibility on Google by implementing SSR (which may sound unbelievable) and achieving a richer preview when content is shared on messaging platforms. As th ...

Is there a way to skip importing React from the test file when using Jest?

I'm currently using testing-library with React Within my test file, I have the following setup: import { render, screen } from '@testing-library/react' import React from 'react' // It would be ideal to avoid including this in each ...

Choose all the checkboxes and set the value of the selected checkbox to 'on' using jQuery

Here is my JSFiddle demonstration featuring a scenario where there are 3 checkboxes. My goal is to assign the value "on" to the selected checkbox, while the unchecked ones should have a value of "off". Initially, I set all checkboxes to have a default va ...

Objects designated as 'invocables' are required

My current state configuration is as follows: .state('core.recover', { url: '/recover', controller: 'RecoverPasswordCtrl', templateUrl: 'views/tmpl/recoverAccount/recover-password.html' }) Upon entering th ...

Is it possible to utilize the return value from an asynchronous function within useEffect as the default value for useState

Check out this simple example I've put together https://codesandbox.io/s/4zq852m7j0. In the example, I am fetching data from a remote source and attempting to use the returned value as the input for my textfield. const useFetch = () => { const ...

Show/Hide Row in Material-UI DataGrid

I need assistance with expanding lines in Material UI. I am trying to create drop-down rows in my table (individually for each row) within a table built using Material UI. Despite researching extensively online, I have been unable to achieve consistent res ...

Is it feasible to have Push Notifications with Phonegap?

I am looking to set up push notifications in my phonegap project for both Android and iOS. My goal is for users to receive a message whenever there is an update on an event. However, I am struggling to grasp the process of achieving this. Is it possible ...

Ways to invoke a class method by clicking on it

My initialization function is defined as follows: init: function() { $("#editRow").click(function() { <code> } $(".removeRow").click(function() { <code> } } I am trying to find a way to call the class method removeRow directly in the onc ...

What is the best way to change the number 123456789 to look like 123***789 using either typescript or

Is there a way to convert this scenario? I am working on a project where the userID needs to be displayed in a specific format. The first 3 characters/numbers and last 3 characters/numbers should be visible, while the middle part should be replaced with ...

When using ng-repeat in Angular JS, only the first element will be displayed on the

I am currently utilizing Angular 1.5.5 function RetrieveDashboardDataForAllEmployees() { var response = eRotaService.RetrieveDashboard(); response.then(function (data) { $scope.weekDays = data.data; console.log(data.data); }, ...

Token generated by Sinch backend for use with Javascript and Android applications

I am currently exploring two distinct methods for creating the sinch authentication token on an app server. One approach is designed for the Android client while the other is tailored for the JS client. Is it feasible to utilize the same token for both the ...

Background of jQuery-UI Slider

Can the background color of a jQuery-UI Slider widget be set using JavaScript? This is the default setting: What I am trying to accomplish is the following: The green range should be determined based on historical data. I want to visually show the user ...

Rephrase the ajax call and the data retrieved

I'm struggling to find a solution for writing this code snippet without using async: false,. var imageX; var groupX; $.ajax({ type:'GET', url:'php/myphp.php', dataType:'json', async: false, success: ...

Executing a function prior to signing up

Is there a way to dynamically add a form control once the user has made a selection? This is my select function: selected(event: MatAutocompleteSelectedEvent): void { this.setTechnologies = new Set(); this.setTechnologies.add(this.techInput.n ...

Tips for utilizing external data sources in React-Native collapsible/accordion components

Incorporating the react-native collapsible/accordion feature into my project has been a great addition. Below is an example I came across: import React, { Component } from 'react-native'; import Accordion from 'react-native-collapsible/Acco ...

Utilizing HighCharts Bubble Graph with JSON Data Feed

I am currently facing an issue with my bubble chart series not plotting, even though I followed the HighCharts example tutorial. I am not seeing any errors on the browser console, which is making it challenging for me to troubleshoot. Here is the data I ...

sending a JavaScript variable's value to a SWF file within FDT

I'm completely new to FDT and I need help passing a javascript variable value to FDT code. This is all brand new to me. Here's the HTML Code snippet: <a id="player" href="javascript:void(0)" data-id="02">ABCD</a> And here's th ...

Using PHP and AJAX to dynamically update the second select option in an HTML table, while also adding new rows using a JavaScript function

Within the image shown, I am dynamically adding rows to a table using JavaScript when the button is clicked: function addRow(dataTable) { "use strict"; var table = document.getElementById("dataTable"); var rowCount = table.rows.length; if( ...

Adding additional text will not render d3.js' output

I'm struggling with a simple issue here, My goal is to add a div to my svg element containing text. I have written the code for this and in the DOM, it shows that the svg has the correct class attached along with the desired text. However, the text i ...