Displaying JSON Object in Kendo UI Grid with Incorrect Format

I encountered an issue where a function that I passed to a Kendo Grid field in the fetch method returns perfectly on console.log, but only [object Object] is returned in the Kendo Grid display.

Here's the background: I am utilizing two services - ReviewService and UserService. The data in the Kendo Grid is fetched using ReviewService, which includes an "id" field. To find the corresponding username from UserService based on the "id", I have created a function and integrated it into the fetch method.

Fetch Method

protected fetch(state: any): Observable<GridDataResult> {
    this.loading = true;
    this.pagination = new Pagination(state.skip, state.take);

  return this.ReviewService.getByCriteria(this.pagination, this.apiVisa)
    .pipe(
      map(
        response =>
          <GridDataResult>{
            data: response["objectList"].map(review => ({
              id: review.id,
              email: this.displayUser(review.id)
            })),
            total: response["totalRecords"]
          }
      ),
      tap(() => (this.loading = false))
    );
  }

Function

public getUser(value): Observable<any> {
  return this.UserService.getByGuid(value, this.apiVisa);
}

public displayUser(id) {
    console.log("GUID: ", id);
    return this.getUser(id)
      .pipe(
      map((x: any) => 
        x.data
      ))
      .subscribe(x => {
        this.getItem = x.username;
        // return this.getItem;
        console.log("Username: ", x.username);
        return x.username;
        // return this.getItem;
      })
  }

Expected Results
In Kendo Grid: Adibah
In console.log: Adibah

Actual Results
In Kendo Grid: [object Object]
In console.log: Adibah

Answer №1

When calling your displayUser function, make sure it returns the actual value of x.username, not just a Subscription. Instead of returning the function from within the .subscribe method, consider using the combineLatest operator to wait for the second observable to complete.

To achieve this, remove the .subscribe from the displayUser function and instead add a combineLatest method to the getByCriteria's pipe chain.

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

Running a TypeScript program that has been compiled with module resolution is not working as expected

I am currently in the process of compiling a TypeScript file with the following code: import { magic } from 'lib/magic'; magic(); The file structure looks like this: ./src/ main.ts lib/ a/magic.ts b/magic.ts Within ...

Utilizing the Redux Connect HOC's wrapped component type in React.RefObject without the need for re-importing

My current setup involves a simple component that is wrapped with react-redux and has a ref with forwardRef: true, demonstrated below: // Button.tsx class Button extends React.Component { // ... } // ... export default connect(mapStateToProps, null, n ...

What is the process of attaching a property to every object within an array using TypeScript?

In my search for adding a property to each object in an array, I came across a solution in AngularJs on Stack Overflow. However, I attempted the following approach which did not yield the desired outcome. Any assistance would be greatly appreciated. ex ...

Remove an item from the DOM instantly with React

Having trouble synchronously removing a child from the container? Here is a simplified code snippet demonstrating the current solution using the useState hook. type ChildProps = { index: number; id: string; remove: (index: number) => void; }; fun ...

Enable the parsing of special characters in Angular from a URL

Here is a URL with special characters: http://localhost:4200/auth/verify-checking/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="59663c34383035643230383d2b606a6e6b686d6e6e193e34383035773a3634">[email protected]</a> ...

Angular 8 - Unraveling the Mystery Behind its Initial Page Discovery

I am facing an issue with my Angular 8 application where the login page is being displayed at startup. I have checked the routing module but couldn't find anything that explicitly sets this page as the startup page. Any suggestions on what might be c ...

Challenges with formArrayName in Angular can be tricky to navigate

I am in the process of developing an Angular library with the main feature being the provision of a selector with two inputs: a reactive form containing the data an object literal specifying which properties of the data should have editable input fields ...

The ASP .Net Core 3.1 Angular template is malfunctioning

https://i.sstatic.net/T3hFx.pngAfter creating a new Web Project using the .Net Core with Angular template in Visual Studio 2019, I encountered an error when trying to build the solution. The error message stated: An unhandled exception occurred while proce ...

What is the method to retrieve the unique individual IDs and count the number of passes and fails from an array

Given a data array with IDs and Pass/Fail statuses, I am looking to create a new array in Angular 6 that displays the unique IDs along with the count of individual Pass/Fail occurrences. [ {"id":"2","status":"Passed"}, {"id":"5","status":"Passed"}, {"id": ...

Testbed: Issue encountered: Unable to resolve all parameters for PriDateInput component

I am facing an issue while creating an Angular Component with the help of TestBed. The error message I receive is as follows: Error: Can't resolve all parameters for PriDateInput: (?). error properties: Object({ ngSyntaxError: true }) ...

Creating a sticky header for a MatTable in Angular with horizontal scrolling

Having an issue with merging Sticky Column and horizontal scrolling. Check out this example (it's in Angular 8 but I'm using Angular 10). Link to Example The base example has sticky headers, so when you scroll the entire page, the headers stay ...

Assign a value to a date field in Aurelia

<input class="" type="date" id="Broken" value.bind="dateval"> The current value of dateval is 2021-04-08T10:05:19.988Z. Is there a way to set a default date for the date input field above? ...

Transform an Array<string> into an object with the strings of the array as keys

I am attempting to develop a type conversion method that transforms an array of strings into an object with the string values as keys. type ObjectFromKeys<T extends Array<string>> = { [K in keyof T]: string } declare const o: ObjectFromKeys& ...

What could be causing Angular's Renderer2 to generate inaccurate outcomes?

Having an array of queries with varying positions of underscores: Newtons __________ Law dictates __________ is the result of an object's mass and speed. My goal is to show each question to users, replacing the blanks with in ...

Angular configuration files fail to be exchanged promptly

I am utilizing Angular 9 with the View Engine compiler. I have two separate files where I hold environment variables: environment.ts: export const environment: any = { production: false, }; environment.prod.ts: export const environment: any = { ...

Exploring the capabilities of .map alongside HTTP requests in Angular 2

I'm curious to know if the use of .map is necessary when making API calls with http in Angular 2. Take a look at my code below. It seems to work both with and without .map. If the API returns data, it signals success; otherwise, it indicates an err ...

Resetting Laravel passwords without relying on user emails, with the additional use of Angular for the front end interface

I'm currently working on a laravel-angular application that requires a password reset feature. However, the default password-reset in Laravel relies on email verification, which is not necessary for this particular application. I tried setting $confir ...

Retrieve information and transform it into a dynamic variable using Firebase

I am trying to retrieve data from the current user, specifically their company named "ZeroMax", and then store this data in a global variable. The purpose of this variable is to define the path for Firebase. I believe my code gives a clear understanding of ...

Show the user's email in the page header using AngularFire2 version 4.0

Attempting to showcase the user's email in my header component following the AngularFire 2 version 4.0 upgrade guidelines: https://github.com/angular/angularfire2/blob/master/docs/version-4-upgrade.md Header.component import { Component, OnInit } fr ...

The system encountered an issue: unable to determine the property 'endsWith' of an undefined value

As I delve into writing my initial unit tests for the components, certain issues have arisen: TypeError: Cannot read property 'endsWith' of undefined. How can I define the data.iconPath in my test to resolve this error? Presenting my component ...