Display an empty value based on condition.

I have a column formatted as currency. If the value of the column is 0, I would like it to display empty string, instead of $0.


What would be the best way to go about that?


3 Replies 1 reply marked as answer

JR Jagadesh Ram Raajkumar Syncfusion Team September 17, 2021 02:23 PM UTC

Hi Zachary,

Greetings from Syncfusion Support. 

To display custom values in a cell based on a condition, you can use queryCellInfo event in treegrid. We have prepared a sample for your reference please refer to it below. In the sample, we have displayed the empty string whenever the cell value is 0. Please refer to the screenshot below.

Screenshot: 


Code Snippet: 
[app.component.ts]

export
class AppComponent { 
    public data: Object[] = []; 
 
    ngOnInit(): void { 
        this.data = sampleData; 
    } 
    cell(args){ 
        if(args.column.field == "duration"){ 
            if(args.data.duration == 0){ 
                args.cell.innerText = ''; 
            } 
        } 
    } 
} 

[app.component.html] 
 
    <ejs-treegrid [dataSource]='data' allowPaging='true' childMapping='subtasks' height='350' [treeColumnIndex]='1' (queryCellInfo)="cell($event)">        <e-columns>            <e-column field='taskID' headerText='Task ID' width='70' textAlign='Right'></e-column>            <e-column field='taskName' headerText='Task Name' width='200'></e-column>            <e-column field='duration' headerText='Duration' width='80' textAlign='Left' format='C0'></e-column>        </e-columns>    </ejs-treegrid>
Documentation: https://ej2.syncfusion.com/angular/documentation/api/treegrid/#querycellinfo

Please get back to us for further assistance.  
Regards,
Jagadesh Ram 


Marked as answer

ZA Zachary September 19, 2021 04:07 PM UTC

Thank you, this worked!



JR Jagadesh Ram Raajkumar Syncfusion Team September 20, 2021 05:22 AM UTC

Hi Zachary, 

Thanks for the update. 
 
We are glad to hear that your query has been solved at your end. 
 
Kindly get back to us for further assistance. We are happy to assist you. 

Regards,
Jagadesh Ram 


Loader.
Up arrow icon