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

Format parent grid column value in subgrid (details template)

7 Answers 256 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hajrija
Top achievements
Rank 1
Hajrija asked on 16 Feb 2016, 12:44 PM

Hello,

I have the next problem.I have a grid that has some columns. One of them is called 'ConfirmedValue'. I know that you use '#' to access a parent grid column in a column's clienttemplate in its subgrid-childgrid (detail template). In a clienttemplate in that subgrid I try to format that column value using:

columns.Template(e => { }).ClientTemplate("# if(ConfirmedValue) { # #= kendo.toString(ConfirmedValue, 'c3') # # } #");

But it is not working. In my browsers dev tool console I get the error "Uncaught Error: Invalid template". I assume the sintax I use is OK. When I use it in my parent grid (main grid) it works well without any problems.

I am not sure if this is a bug or if kendo does not support this kind of behaviour. 

Can you please help me out? What did I do wrong?

Best regards,

 

 

 

 

 

7 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 18 Feb 2016, 10:04 AM
Hi Hajrija,

To achieve the desired functionality you need to escape the "#" sign in the client template of the detail grid:
columns.Bound(p => p.ConfirmedValue).ClientTemplate("\\# if(ConfirmedValue) { \\# \\#= kendo.toString(ConfirmedValue, 'c3') \\# \\# } \\#");

Additionally I am sending you a simple example which demonstrates this.

I hope this helps.

Regards,
Radoslav
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Shoeb
Top achievements
Rank 1
answered on 27 Sep 2016, 02:11 PM

Hi,

I am trying to do the same but it’s not working. If you can let me know what’s going off that would be a great help.

I Have a parent grid and child grid. I am trying to use the below template to calculate the max quantity and I am getting error invalid template.

columns.Bound(o => o.ConfigurationStatusId).ClientTemplate("\\# if(CodeConfigurationStatus.CodeLookupId != 1) {\\#  \\#=kendo.toString( \\#=Quantity \\# * \\#= Product.QuantityOfChoiceItems \\#)\\# \\#} else {\\# \\#=Quantity \\# \\#} \\#").Title("Max QTY");   

Error :

Uncaught Error: 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  role='gridcell'>#:data.CodeConfigurationStatus.Name==null?'':data.CodeConfigurationStatus.Name#</td><td  role='gridcell'>#:data.Product.PartNumber==null?'':data.Product.PartNumber#</td><td  role='gridcell'>#:data.Quantity==null?'':data.Quantity#</td><td  role='gridcell'>false</td><td  role='gridcell'>AR-FS-BNDL-3</td><td style="display:none" role='gridcell'>1</td><td style="display:none" role='gridcell'>36678</td><td  role='gridcell'># if(CodeConfigurationStatus.CodeLookupId != 1) {#  #=kendo.toString( #=Quantity # * #= Product.QuantityOfChoiceItems #)# #} else {# #=Quantity # #} #</td></tr>' Generated code:'var $kendoOutput, $kendoHtmlEncode = kendo.htmlEncode;with(data){$kendoOutput='<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  role=\'gridcell\'>'+$kendoHtmlEncode(data.CodeConfigurationStatus.Name==null?'':data.CodeConfigurationStatus.Name)+'</td><td  role=\'gridcell\'>'+$kendoHtmlEncode(data.Product.PartNumber==null?'':data.Product.PartNumber)+'</td><td  role=\'gridcell\'>'+$kendoHtmlEncode(data.Quantity==null?'':data.Quantity)+'</td><td  role=\'gridcell\'>false</td><td  role=\'gridcell\'>AR-FS-BNDL-3</td><td style="display:none" role=\'gridcell\'>1</td><td style="display:none" role=\'gridcell\'>36678</td><td  role=\'gridcell\'>'; if(CodeConfigurationStatus.CodeLookupId != 1) {;$kendoOutput+='  '+(kendo.toString( )+'=Quantity '; * ;$kendoOutput+='= Product.QuantityOfChoiceItems ';);$kendoOutput+=' ';} else {;$kendoOutput+=' '+(Quantity )+' ';} ;$kendoOutput+='</td></tr>';}return $kendoOutput;'

 

 

Thanks,
Shoeb.

0
Shoeb
Top achievements
Rank 1
answered on 28 Sep 2016, 07:36 PM
can someone, please help me on this ?
0
Hajrija
Top achievements
Rank 1
answered on 29 Sep 2016, 08:41 AM

I will assume that all fields belong to the child grid. If that is the case, can you try this please:

columns.Bound(o => o.ConfigurationStatusId).ClientTemplate("\\# if(CodeConfigurationStatus.CodeLookupId != 1) {\\#  \\#=kendo.toString( Quantity *  Product.QuantityOfChoiceItems )\\# \\#} else {\\# \\#=Quantity \\# \\#} \\#").Title("Max QTY"); 

I think that you do not need to use kendo.toString. You can write it this ways too:

columns.Bound(o => o.ConfigurationStatusId).ClientTemplate("\\# if(CodeConfigurationStatus.CodeLookupId != 1) {\\#  \\#=Quantity*Product.QuantityOfChoiceItems \\# \\#} else {\\# \\#=Quantity \\# \\#} \\#").Title("Max QTY"); 

 

Tell me if that fixed your problem.

0
Viktor Tachev
Telerik team
answered on 29 Sep 2016, 10:59 AM
Hello,

Try to extract the logic from the ClientTemplate in external JavaScript function and see how the behavior changes. Check out the example below that illustrates the approach:



Regards,
Viktor Tachev
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Shoeb
Top achievements
Rank 1
answered on 30 Sep 2016, 02:45 PM

Hi Hajrija,
That worked. Thanks for your Help :)

Thanks,

Shoeb.

0
Shoeb
Top achievements
Rank 1
answered on 30 Sep 2016, 02:47 PM

Hi Viktor,
Thanks for your response. I was not aware that we can user ClientTemplate  in this way.

Thanks,

Shoeb.

Tags
Grid
Asked by
Hajrija
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Shoeb
Top achievements
Rank 1
Hajrija
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or