This is a migrated thread and some comments may be shown as answers.

globalization problem

3 Answers 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Przemek
Top achievements
Rank 1
Przemek asked on 16 Nov 2012, 08:22 AM
I have grid with client detail template:

@(Html.Kendo().Grid<SalesOrderModel>()
      .Name("SalesOrders")
      .Columns(columns =>
          {
              columns.Bound(e => e.Number).Width(20).ClientTemplate(Html.ActionLink("#=Number#", "Edit", "SalesOrder", new { id = "#=Id#" }, null).ToHtmlString());
              columns.Bound(e => e.Status).Width(20);
              columns.Bound(e => e.ContractorName).Width(200);
              columns.Bound(e => e.CreatedDate).Width(40).Format("{0:d}");
          })            
      .ClientDetailTemplateId("itemsTemplate")
      .Pageable()
      .DataSource(dataSource => dataSource
                                    .Ajax()
                                    .Read(read => read.Action("LoadData", "SalesOrder"))
                                    .PageSize(40)
      )
      .Sortable()
      .Filterable())
<script id="itemsTemplate" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<SalesOrderItem>()
            .Name("Items_#=Id#")
            .Columns(columns =>
            {
                columns.Bound(o => o.Position).Width(20);
                columns.Bound(o => o.Index).Width(100);
                columns.Bound(o => o.Name).Width(200);
                columns.Bound(o => o.Quantity).Width(20);
                columns.Bound(e => e.UnitOfMeasure).Width(20);
            })
            .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action("LoadItems", "SalesOrder", new { salesOrderId = "#=Id#" }))
            )
            .Pageable()
            .Sortable()
            .ToClientTemplate()
    )
</script>

and everything worked perfectly until now. I changed globalization section in web.config from
<globalization enableClientBasedCulture="true" culture="auto" /> 
to 
<globalization enableClientBasedCulture="false" culture="pl-PL" uiCulture="pl-PL" />
After this change exception is throwing by javascript "Invalid template ..."
Note that everything woks good except master-detail grid described above.

3 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 21 Nov 2012, 08:59 AM
Hello Przemek,

Thank you for providing details about your setup. We investigated your case and we found that the problem for this issue is because one of the translated messages for the pager contains a special symbol รณ to the Html which is encoded by the Razor engine and thus an invalid detail template is generated.
I can suggest you two work-arounds for such case.
  1. Change the localization message manually like this so it does not contain such symbol:
    .Pageable(pager => pager.Messages(msg => msg.Display("Wyswietlanie elementow {0} - {1} z {2}")))
  2. If you want to keep the special symbols you need to escape the sharp symbol (#) in its encoded Entity Number equivalent and use the Raw html helper.
    e.g.
    <script id="itemsTemplate" type="text/kendo-tmpl">
        @Html.Raw(Html.Kendo().Grid<Person>()
                .Name("Items_#=PersonID#")
                .Columns(columns =>
                {
                    columns.Bound(c => c.PersonID);
                    columns.Bound(c => c.Name);
                })
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .Read(read => read.Action("GetPersons", "Home"))
                )
                .Pageable()
                .Sortable()
                .ToClientTemplate().ToString().Replace("&#","&\\#")
        )
    </script>
I hope this helps.

Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Przemek
Top achievements
Rank 1
answered on 21 Nov 2012, 11:28 AM
Its works! Thank you!
0
2Trace
Top achievements
Rank 1
answered on 03 Jun 2013, 10:16 AM
This is still an issue with 2013.1.514. How can that be?

I have tried the replace thing(it's not a good solution) - it works for the danish translation, but not french. Please advise ASAP as this is critical to our customers.

Here is a dump of the JS error(without the replace):

Invalid template:'<tr class="k-master-row" data-uid="#=data.uid#" role='row'><td class="k-hierarchy-cell"><a class="k-icon k-plus" href="\#" tabindex="-1"></a></td><td hideFromColumnPicker="True"shortenRowValues="True"fieldType="string"style="display:none" role='gridcell'>#:data.ZoneId==null?'':data.ZoneId#</td><td style="text-align:left;white-space:nowrap;"shortenRowValues="True"fieldType="string" role='gridcell'>#:data.Name==null?'':data.Name#</td><td hideFromColumnPicker="True"shortenRowValues="True"fieldType="number"style="display:none" role='gridcell'>#:data.Age==null?'':data.Age#</td><td style="text-align:right;white-space:nowrap;"shortenRowValues="True"fieldType="number" role='gridcell'>#:data.ItemCount==null?'':data.ItemCount#</td><td style="text-align:right;white-space:nowrap;"shortenRowValues="True"fieldType="number" role='gridcell'>#= AverageTime != null ? kendo.toString(AverageTime, 'n1') : 'Je n'ai jamais vu'# #= AverageTime != null ? 'jours':''#</td></tr>' Generated code:'var o,e=kendo.htmlEncode;with(data){o='<tr class="k-master-row" data-uid="'+(data.uid)+'" role=\'row\'><td class="k-hierarchy-cell"><a class="k-icon k-plus" href="#" tabindex="-1"></a></td><td hideFromColumnPicker="True"shortenRowValues="True"fieldType="string"style="display:none" role=\'gridcell\'>'+e(data.ZoneId==null?'':data.ZoneId)+'</td><td style="text-align:left;white-space:nowrap;"shortenRowValues="True"fieldType="string" role=\'gridcell\'>'+e(data.Name==null?'':data.Name)+'</td><td hideFromColumnPicker="True"shortenRowValues="True"fieldType="number"style="display:none" role=\'gridcell\'>'+e(data.Age==null?'':data.Age)+'</td><td style="text-align:right;white-space:nowrap;"shortenRowValues="True"fieldType="number" role=\'gridcell\'>'+e(data.ItemCount==null?'':data.ItemCount)+'</td><td style="text-align:right;white-space:nowrap;"shortenRowValues="True"fieldType="number" role=\'gridcell\'>'+( AverageTime != null ? kendo.toString(AverageTime, 'n1') : 'Je n'ai jamais vu')+' '+( AverageTime != null ? 'jours':'')+'</td></tr>';}return o;'

UPDATE

It seems to be related to ClientTemplates. They cannot hold special characters. For example, "Je n'ai jamais vu". I think this is a flaw that should be fixed. As well as not having to add .Replace("&#", "&\\#") to each ToClientTemplate()
Tags
Grid
Asked by
Przemek
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Przemek
Top achievements
Rank 1
2Trace
Top achievements
Rank 1
Share this question
or