- Home
- Forum
- ASP.NET MVC (Classic)
- Format in Grid Column Template
Format in Grid Column Template
I have a grid, with a column template, and it works just fine, the issue is that I want to format de output as currency, and it has no effect
This is the only way I know to make a link column, and I have tried many ways to format the column, but none has effect. Could anyone please help me?
The template
<script type="text/x-jsrender" id="columnTemplate">
{{if CXC > 0}}
<a id="cobrar" rel='nofollow' href="[email protected]&[email protected]&semana={{:Key}}&moneda=Mexican Peso&[email protected]&[email protected]">$ @String.Format("{0:N}", "{{CXC}}")</a>
{{else}}
$ 0.00
{{/if}}
</script>
the grid
@(Html.EJ().Grid<Object>("Cashflow")
.Datasource((IEnumerable<object>)Model.CashFlow())
.AllowPaging()
.Columns(col =>
{
col.Field("Key").HeaderText("Semana").IsPrimaryKey(true).TextAlign(TextAlign.Center).Width(75).Add();
col.Field("CXC").HeaderText("Cuentas por Cobrar").Template("#columnTemplate").TextAlign(TextAlign.Center).Width(110).Add();
})
)
SIGN IN To post a reply.
3 Replies
IR
Isuriya Rajan
Syncfusion Team
September 26, 2016 11:29 AM UTC
Hi Dayne,
Thanks for contacting Syncfusion support.
You can achieve your requirement by using the grid Templaterefresh event. This event will be triggered when you refresh the template column elements in the Grid. Here you can set the format for the corresponding cell value.
Please refer to the below code example:
|
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.Columns(col =>
{
col.HeaderText("Template column").Template(true).TemplateID("#columnTemplate").TextAlign(TextAlign.Center).Width(110).Add();
col.Field("City").Width(100).Add();
col.Field("Country").Width(100).Add();
})
.ClientSideEvents(evt=>evt.TemplateRefresh("template"))
)
<script>
function template(args) {
$(args.cell).find("a").text(ej.format(args.data.Freight, "C2"))
}
</script>
<script type="text/x-jsrender" id="columnTemplate">
{{if Freight < 30}}
{{else}}
{{/if}}
</script> |
Note: Here we have formatted the freight column.
Please refer to the sample from the link attached: http://www.syncfusion.com/downloads/support/directtrac/general/COLUMN~1-70534189.ZIP
Regards,
Isuriya R .
DA
Dayne
September 26, 2016 02:14 PM UTC
Thanks !! This solucion works just fine.
IR
Isuriya Rajan
Syncfusion Team
September 27, 2016 05:31 AM UTC
Hi Dayne,
Thanks for the update. We are happy to assist you.
Regards,
Isuriya R.
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
DA Dayne
- Sep 23, 2016 03:10 PM UTC
- Sep 27, 2016 05:31 AM UTC