how to format the cell in the numeric column in sfdatagrid

hi

I have sfdatagrid has a column (numeric column) but the values in that column:

10.5

10.55

10.555

0.000067

but the data appear as following values:

10.50

10.55

10.56

0.00

How to solve this problem??

I want to keep the value and show it as it is coming from the database in each row.


8 Replies 1 reply marked as answer

SB Sweatha Bharathi Syncfusion Team September 8, 2023 01:40 PM UTC

Hi Mohamad ,


We have analyzed your query, and we understand your requirement. It can be achieved by setting the Format property of the GridNumericColumn to display the values without rounding. For example, you can use "0.###" as the format to display up to three decimal places without rounding. We have provided the sample for your reference . Kindly review the sample and let us know if you have any concerns on this .


Image Reference :







Attachment: Sample_99a32bd4.zip


MO Mohamad September 12, 2023 10:25 PM UTC

thank you, it's working now but when I try to edit the number via SfDatagrid directly I can't write more than 2 decimal value!! why? how can I solve the problem?

Image_4612_1694557540440



SB Sweatha Bharathi Syncfusion Team September 13, 2023 02:14 PM UTC

Mohamad ,


We have analyzed your query, and your reported issue is related to our dependency control. We have checked with the concerned team, and we need time to validate this . We will update further details on September 15,2023.



SB Sweatha Bharathi Syncfusion Team September 15, 2023 01:53 PM UTC

Mohamad ,


We have analyzed your query, and your requirement can be achieved by customizing the GridNumericCellRenderer and changing the SfNumericTextBox validation mode to 'LostFocus'. We have provided the sample for your reference . Kindly review the sample and let us know if you have any concerns on this.




Code Snippet :


 
this.sfDataGrid.CellRenderers.Remove("Numeric");

this.sfDataGrid.CellRenderers.Add("Numeric", new GridNumericCellCellRendererExt());



public class GridNumericCellCellRendererExt : GridNumericCellRenderer

  {

     protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, SfNumericTextBox uiElement)

     {

 

         base.OnInitializeEditElement(column, rowColumnIndex, uiElement);

         uiElement.ValidationMode = Syncfusion.WinForms.Input.Enums.ValidationMode.LostFocus;

     }

  }

 



Attachment: Sample_9fcda39b.zip

Marked as answer

MO Mohamad September 16, 2023 12:01 PM UTC

thanks, but when I write the value I see there is "00" in the last of the number (during the writing) how can hide that 00 when writing?



VS Vijayarasan Sivanandham Syncfusion Team September 18, 2023 04:20 PM UTC

Mohamad,

Your requirement to hide the trailing zeros in the GridNumericColumn can be achieved by enabling the HideTrailingZeros property in the loaded edit element of SfNumericTextBox. Refer to the below code snippet,

//Remove existing Numeric Renderer

this.sfDataGrid.CellRenderers.Remove("Numeric");

//Add customized Numeric Renderer

this.sfDataGrid.CellRenderers.Add("Numeric", new GridNumericCellCellRendererExt());

 

//Custom cell renderer to customize the SfNumericTextBox

public class GridNumericCellCellRendererExt : GridNumericCellRenderer

{

    // Override the OnInitializeEditElement method to customize the SfNumericTextBox

    protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, SfNumericTextBox uiElement)

    {         

        base.OnInitializeEditElement(column, rowColumnIndex, uiElement);

        //Hide the trailing zeros

        uiElement.HideTrailingZeros = true;

        uiElement.ValidationMode = ValidationMode.LostFocus;

    }       

}


Find the sample demo in the attachment.

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: SfDataGridDemo_97502c68.zip


MO Mohamad September 20, 2023 09:53 AM UTC

when I applied your solution I got the error that I you can see in attachment video.



Attachment: explain_e5e4a60d.rar


SG Santhosh Govindasamy Syncfusion Team September 21, 2023 11:15 AM UTC

Hi Mohamad,

We were not clear with your reported error, and we can’t get this from attached video. Furthermore, we reviewed the provided sample, and it appeared to function as expected. To assist us in resolving your query, please provide additional details regarding the specific error you encountered. This information will be invaluable in helping us address your issue effectively.


Regards,
Santhosh.G


Loader.
Up arrow icon