Want to show hyphen in replace 0.00 value and () for negative values

Image_6183_1729546815018

I want to replace 0.00 with hyphen and if value is negative like -7,000 then (7,000) 

Please help 



1 Reply

AR Aishwarya Rameshbabu Syncfusion Team October 22, 2024 09:31 AM UTC

Hi RJ,


Greetings from Syncfusion support.


Based on the information provided, it has been observed that you wanted to customize the cell values based on the data bound to the Syncfusion Grid. To address your requirement, we have developed a sample where we utilized the queryCellInfo event of the Grid to customize the values of the cells according to your requirement. Please refer to the code example, sample, and screenshot below for more detailed information.


Index.cshtml

 

<div>

    <ejs-grid id="grid01" dataSource="@ViewBag.DataSource" allowPaging="true" allowSorting="true" queryCellInfo="queryCellInfo">

        <e-grid-columns>

                 …………………………………….

        </e-grid-columns>

    </ejs-grid>

</div>

<script>

  function queryCellInfo(args) {

    let value = args.data[args.column.field];

    if (typeof value === 'number') {

      if (value === 0) {

        args.cell.innerHTML = '-'; // Show hyphen for 0

      } else if (value < 0) {

        args.cell.innerHTML = `(${Math.abs(value)})`; // Show parentheses for negative values

      }

    }

  }

</script>

 


Sample: Please find in the attachment.


Screenshot:



API Reference: queryCellInfo


If you need any other assistance or have additional questions, please feel free to contact us.


Regards

Aishwarya R


Attachment: 194885Sample_b42cc853.zip

Loader.
Up arrow icon