Grid column format

Hi

I want show numbers in my grid in thousands and millions. Is it posible? 
Value in column is 1000000 and i want transform it to 1000 K and 1 M.

1 Reply

MF Mohammed Farook J Syncfusion Team October 11, 2018 01:03 PM UTC

Hi Devw, 
 
Thanks for contacting Syncfusion support. 
 
Query: I want show numbers in my grid in thousands and millions. Is it posible? Value in column is 1000000 and i want transform it to 1000 K and 1 M. 
 
We have validated your query and you can achieve your requirement by using  QueryCellInfo event. Please find the below code example for your reference. 
 
[code example] 
... 
    let grid: Grid = new Grid( 
        { 
            dataSource: gridData, 
            editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' }, 
           allowPaging: true, 
            pageSettings: { pageCount: 5 }, 
            toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'], 
            columns: [ 
                ... 
               queryCellInfo: customiseCell 
        }); 
    grid.appendTo('#Grid'); 
 
function customiseCell(args: QueryCellInfoEventArgs){ 
  debugger; 
   if(args.column.field === 'Freight') { 
 
  let value : any  = prettifyNumber(args.data['Freight']); 
  args.cell.innerHTML = value; 
} 
} 
 
function prettifyNumber(value) { 
  //de 
    var thousand = 1000; 
    var million = 1000000; 
     var billion = 1000000000; 
    if (value < thousand) { 
        return String(value);    
    } 
     
    if (value >= thousand && value <= 1000000) { 
         return  Math.round(value/thousand) + 'k';    
    } 
     
    if (value >= million && value <= billion) { 
        return Math.round(value/million) + 'M';    
    } 
    } 
 
We have prepared a sample based on your requirement. Please find the sample in below link. 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
J Mohammed Farook 
 


Loader.
Up arrow icon