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

Is there a sweet TypeScript class constructor that can take in its own instance as an argument?

I have a scenario where I need to read in instances of Todo from a CSV file. The issue is that Papaparse does not handle dynamic conversion on dates, so I'm currently dropping the object into its own constructor to do the conversion: class Todo { ...

Utilizing ngx-pagination for repetitive instances of a single component

I have encountered an issue with the ngx-pagination library in my reusable data table component. While it works perfectly for a single instance, using it multiple times causes the pagination to only function on one of the components. Is there a way to make ...

The Angular route successfully navigated to the page, but the HTML content was not

Whenever I select the Home option in the navigation bar, it takes me to the home URL but doesn't display the HTML content. Below is my app.routing.module.ts code: import { Component, NgModule } from '@angular/core'; import { RouterModule, Ro ...

Navigating with Angular: The URL for the home page should be set as http://localhost:4200/

I recently implemented URL routing in my project, but I have encountered an issue. Upon redirecting to the home page, the URL changes to http://localhost:4200/home. However, I would like the URL for the home page to simply be http://localhost:4200/ instea ...

Creating a unique optional string array interface in TypeScript

I am looking to create an interface that includes optional string values. Here is what I have in mind: interface IEntity { values: ['RemainingUnits', 'ActualUnits', 'PlannedUnits'] } However, when implementing this inter ...

Do you think it's important to include a maxlength validation message for an input field in Angular?

Utilizing the maxlength attribute on a form field not only enables Angular's default validation, it also restricts input beyond the specified length from being typed into the text box. So, does this imply that displaying an error message for violating ...

Managing Deactivated Elements in Ionic Web Edition

In my extensive ionic application that I deploy to both the Web and mobile platforms, a member of the testing team brought to my attention an issue regarding disabled elements. I have numerous elements such as buttons, checkboxes, inputs, etc., which can b ...

Is it possible to deduce the output type of a function based on its input?

In a web development project, the function getFormData() plays a crucial role in validating and sanitising a FormData object based on a specified schema. If the validation process goes smoothly without any errors, the function will return the cleansed Form ...

Getting the specific nested array of objects element using filter in Angular - demystified!

I've been attempting to filter the nested array of objects and showcase the details when the min_age_limit===18. The JSON data is as follows: "centers": [ { "center_id": 603425, "name" ...

Is it feasible to link an Angular property value to the value of an HTML data attribute?

Can an Angular property value be bound to a data attribute on a template element? <h1 data-name="{{name}}">Hello from {{ name }}!</h1> Example Link After running the code, it results in the following error: Error in src/main.ts (11: ...

Using WebdriverIO with Angular to create end-to-end tests in TypeScript that involve importing classes leads to an error stating "Cannot use import statement outside a module."

I am facing an issue while trying to set up a suite of end-to-end tests using wdio. Some of the tests utilize utility classes written in TypeScript. During the compilation of the test, I encountered the following error: Spec file(s): D:\TEMP\xx& ...

Narrowing down the keys of an indexable type in TypeScript based on their corresponding value types

If I have a generic indexable type, how can I retrieve the types of its values in order to narrow down to specific keys? // Let's assume check is a function that only allows the property 'a' as a string and raises an error if 'b' ...

Exploring the process of manually establishing a route change stream in Angular versus utilizing the features of the @angular/router module

Why would a developer choose to manually create a stream of route changes instead of utilizing Angular's ActivatedRoute as recommended in the Angular guide? export class HeroListComponent implements OnInit { heroes$: Observable<Hero[]>; pr ...

What is the process for displaying the attributes of a custom object in Typescript?

I need help returning an array of prop: value pairs for a custom object using the myObject[stringProp] syntax. However, I keep encountering this error message: TS7053: Element implicitly has an 'any' type because expression of type 'str ...

Utilize Hostbinding in Angular to Inject Style Declarations

Is there a way to efficiently inject multiple style declarations into a component using the @HostBinding decorator? I've been attempting the following: @HostBinding('style') get style(): CSSStyleDeclaration { return { background: &apo ...

The TypeScript compiler is generating node_modules and type declaration files in opposition to the guidelines outlined in the tsconfig.json file

For the past week, I've been trying to troubleshoot this issue and it has me completely puzzled. What's even more puzzling is that this app was compiling perfectly fine for months until this problem occurred seemingly out of nowhere without any c ...

Spring Boot - The Ultimate Guide to Hosting Angular2 Compiled Files

Currently, I am using a Spring Boot restful server alongside an Angular2 front-end application. In an attempt to streamline the process, I have been trying to host the front-end files on Tomcat in order to avoid serving them separately. Unfortunately, desp ...

What is the reason behind Angular not allowing users to define @Output events that begin with 'on'?

While developing a component, I defined an output EventEmitter named onUploaded. However, Angular flagged an error instructing me to use (uploaded) instead. This restriction is due to security concerns, as bindings starting with 'ono' pose risks. ...

Ways to verify and incorporate https:// in a URL for a MEAN Stack application

When extracting the URL from API data, my code looks like this: <div class="row copy-text"> <a href="{{copy.Url}}" target="_blank" style="text-decoration: underline !important;">{{copy.Title}}</a> </div> I am interested in ve ...

What could be the reason it's not functioning as expected? Maybe something to do with T extending a Record with symbols mapped

type Check<S extends Record<unique, unknown>> = S; type Output = Check<{ b: number; }>; By defining S extends Record<unique, unknown>, the Check function only accepts objects with unique keys. So why does Check<{b:number}> ...