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
close icon

IGridColumnBuilder Format(string content) does not format string types

Hi,

I want to format (e.g. (123) 456-7890) the values in the Telephone field when displayed in the grid. Below is my code in cshtml. Note that Telephone has a "string" data type.


@{ Html.Syncfusion().Grid<AutoFormatting>("FormatGrid")

.Datasource(Model)

.ShowCaption(false)

.ShowRowHeader(false)

.AutoFormat(Skins.Sandune)

.Column( column =>

{

column.Add(c => c.Telephone)

                                   .HeaderText("Telephone")

                                   .Format("{0:(###) ###-####}");

                    }).Render();

}


Currently, formatting does not work for string types. Do you have any work around aside from creating another field with int or int64 type?

Thanks.

1 Reply

AM Abdul Matin M Syncfusion Team June 21, 2013 12:16 PM UTC

Hi Ronaldo,

 

Thanks for using Syncfusion Products.

 

Your requirement to format string data type can be achieved using QueryCellInfo event. In QueryCellInfo event we have did formatting by converting the string to integer and again converted the result back to string and displayed the formatted string in the grid. Could you please refer the below code snippet.

 

[Controller]

public void QueryCellInfo(GridTableCell<AutoFormatting> cell)

        {

            if (cell.TableCellType == GridTableCellType.RecordFieldCell || cell.TableCellType == GridTableCellType.AlternateRecordFieldCell)

            {

                if (cell.Column.MappingName == "Telephone")

                {

                    cell.Text = Convert.ToInt64(cell.Data.Telephone).ToString("(###) ###-####");

                }

            }

        }

 

For your convenience we have attached a sample. Could you use that sample and get back to us if you have any queries.

 

Let us know if you have any other concerns.

 

Regards,

Abdul Matin M.



StringFormatting_c1bf9ff5.zip

Loader.
Live Chat Icon For mobile
Up arrow icon