We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Format value

Hi, 

I have a grid that have a cell that may contains two types of formats, based in lengtn of your value.

How can I correctly set my cell format?

The formats are: when value length is 14: 00.000.000/0000-00 and when is 11: 000.000.000-00.


1 Reply

PS Pavithra Subramaniyam Syncfusion Team March 12, 2019 06:07 AM UTC

Hi Benjamim, 
 
Greetings from Syncfusion, 
 
You can achieve your requirement by using the column.valueAccessor property of Grid component. Please refer to the below code example, documentation link and sample link for more information. 
 
[component.ts] 
@Component({ 
    selector: 'control-content', 
    template: '  <ejs-grid [dataSource]='data' height='350'> 
        <e-columns> 
            <e-column field='OrderID' headerText='Order ID' [valueAccessor]='valueAccess' width='120' textAlign='Right'></e-column> 
             .   .   . 
        </e-columns> 
    </ejs-grid>' 
}) 
export class DefaultComponent implements OnInit { 
    public data: Object[] = []; 
      
    public valueAccess = (field: string, data: Object, column: Object) => {      
        return data[field].toString().length == 5 ? this.format("###0.##0#",data[field]):this.format("0000 %",data[field]); 
    } 
    ngOnInit(): void { 
        this.data = orderDetails; 
    } 
    format(format,value){ 
       let intl: Internationalization = new Internationalization(); 
       let nParser: Function =  intl.getNumberParser({ format:format}); 
       let val: string = intl.formatNumber(value,{format: format }) 
      return val; 
    }} 
 
 
 
Please get back to us, if you need further assistance. 
 
Regards, 
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon