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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

IGridColumnBuilder Format(string content) does not format string types

Thread ID:

Created:

Updated:

Platform:

Replies:

109545 Jun 19,2013 05:42 AM Jun 21,2013 08:16 AM ASP.NET MVC (Classic) 1
loading
Tags: Grid
Ronaldo Macapobre
Asked On June 19, 2013 05:42 AM

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.

Abdul Matin M [Syncfusion]
Replied On June 21, 2013 08:16 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;