0

I have ag-grid and from service I get data that i show in grid like this:

My ts code looks like this:

constructor( private codeService: CodeService ) {
        this.columnDefs = [
                 { headerName: "Name", field: "name"},
                 { headerName: "Property", field: "properties", editable: true },
                            ];
    }

    ngOnInit() {
        this.codeService.getCodeType( this.name ).subscribe(
                response => { this.handleSuccess( response ); },
                error => { console.error( error ); });

    }

    handleSuccess( aaTypes ) {
        var data = [];
        aaTypes.forEach( ( aaType ) => {
            var entriesForType = [];
            entriesForType.push( aaType );    
                if ( entriesForType.length > 0 ) {
                    entriesForType.forEach( entry => data.push( entry ) );
                    this.data = data;
                    if(this.gridOptions.api !== null){
                        this.gridOptions.api.setRowData( data );
                    }
                } 
        });
    }

As you can see... properties are actually object and it shows like that in grid on picture one ...My question is, is there any way for me to stringify that "properties" so it will show like string and not object.. Im ok if it shows something like "{location: 0, color; 255}".

2
  • did you try this ag-grid.com/javascript-grid-value-getters/… Commented Dec 20, 2017 at 19:13
  • I have seen this, but I don't quite understand how can I apply in my case, but it seem that this is just what I need. @Sajeetharan Commented Dec 20, 2017 at 19:18

1 Answer 1

3

Add a valueFormatter to your columnDefs and create the formatter:

constructor( private codeService: CodeService ) {
    this.columnDefs = [
             { headerName: "Name", field: "name"},
             { headerName: "Property", field: "properties", valueFormatter: jsonFormatter, editable: true },
                        ];
}

function jsonFormatter(d) {
     return JSON.stringify(d);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.