|
<SfGrid DataSource="@Orders" Height="315">
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="<span> Order ID </span>" DisableHtmlEncode="false" TextAlign="TextAlign.Right" Width="140"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="<span> Customer ID </span>" DisableHtmlEncode="false" Width="120"></GridColumn>
. . .
</GridColumns>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
protected override void OnInitialized()
{
Orders = Enumerable.Range(1, 75).Select(x => new Order()
{
OrderID = 1000 + x,
CustomerID = (new string[] { "ALFKI <br /> From <br /> Tokyo", "ANANTR <br /> from <br /> German", "ANTON <br /> from <br />", "BLONP <br /> Oslo", "BOLID" })[new Random().Next(5)], //datasource containing break tags
ShipCity = (new string[] { "Seattle", "Tacoma", "Redmond", "Kirkland", "London" })[new Random().Next(5)],
OrderDate = DateTime.Now.AddDays(-x),
}).ToList();
}
. . .
} |
|
|
|
<SfGrid DataSource="@Orders" Height="315">
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="<span> Order ID </span>" DisableHtmlEncode="false" TextAlign="TextAlign.Right" Width="140"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="<span> Customer ID </span>" DisableHtmlEncode="false" Width="120">
<Template>
@{
var employee = (context as Order);
string[] words = employee.CustomerID.Split(' '); //here we have split the words
foreach (var word in words)
{
<div> @word <br /></div> //displayed multiple lines
}
}
</Template>
</GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" Width="100"></GridColumn>
</GridColumns>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
protected override void OnInitialized()
{
Orders = Enumerable.Range(1, 75).Select(x => new Order()
{
OrderID = 1000 + x,
CustomerID = (new string[] { "ALFKI from Tokyo", "ANANTR from German", "ANTON from Berlin", "BLONP Oslo", "BOLID" })[new Random().Next(5)],
ShipCity = (new string[] { "Seattle", "Tacoma", "Redmond", "Kirkland", "London" })[new Random().Next(5)],
OrderDate = DateTime.Now.AddDays(-x),
}).ToList();
}
. . .
} |
|
|
Another thing you can do with the original data is transform it to HTML, so something like this in the model:
{
...
var htmlValue = originalValue.Replace("\r\\ n", "
");
// And if you want OS-agnostic returns add these:
htmlValue = htmlValue.Replace("\r", "
");
htmlValue = htmlValue.Replace("", "
");
...
}
Then, display the htmlValue in the SfGrid column with `DisableHtmlEncode="false"`.
(NOTE: The post editor on this website didn't display return/newline code above, so I had to add a space to show it... Third Replace has newline character in quotes. Also I am replacing it with HTML break tag.)
Hi coda,
Thanks for your suggestions
Regards,
Naveen Palanivel