This is a migrated thread and some comments may be shown as answers.
DisplayTemplate not working
2 Answers 70 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Amitesh
Top achievements
Rank 1
Amitesh asked on 29 Jul 2010, 10:59 PM
Hi
I am having issues where a combo box column is not displaying the selected value when in display mode. It just shows [Object object]. Also if I edit the row, the column is not remembering the selected item. The "GST Code" column is the problem column

I have my display template and edit templates all defined

Below is my code for the grid:
<%= Html.Telerik()
                               .Grid(Model.InvoiceLineItems)
                               .Name("InvoiceLineItemGrid")
                               .DataKeys(keys =>
                               {
                                   keys.Add(i => i.StagingId).RouteKey("StagingId");
                               })
                               .ToolBar(commands => commands.Insert())
                               .DataBinding(dataBinding =>
                               {
                                   dataBinding.Ajax()
                                       .Select("GetEnteredInvoiceLineItems", "SupplierInvoice")
                                       .Insert("InsertLineItem", "SupplierInvoice")
                                       .Update("EditLineItem", "SupplierInvoice");
                               })
                               .Columns(columns =>
                               {
                                   columns.Bound(i => i.TaxCode).Title("GST Code");
                                   columns.Bound(i => i.UnitCost.Tax).Title("GST");
                                   columns.Bound(i => i.UnitDescription).Title("Unit Description");
                                   columns.Command(commands => { commands.Edit(); }).Width(150).Title("Actions");
                               })
                               .ClientEvents(events => events
                                   .OnRowDataBound("InvoiceLineItemGrid_OnRowDataBound"))
                               .Scrollable()
                           %>

Below is my code for display template:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ViewModels.Portal.TaxCodeViewModel>" %>
<%= Html.Encode(Model.Code) %>

2 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 30 Jul 2010, 12:27 PM
Hi Amitesh,

DisplayTemplate is supported only with server binding. To achieve your goal you need to use ClientTemplate method of the grid column like so:
.ClientTemplate("<# if (TaxCode) { #> <#= TaxCode.Code#>  <#} else { #> none <# } #>");

Greetings,
Georgi Krustev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Amitesh
Top achievements
Rank 1
answered on 02 Aug 2010, 12:25 AM
Hi Georgi
Thanks for the reply. I did actually end up imlementing the solution the way you described. I have another problem though. My grid has multiple columns and the first column contains the Id. On row selection I do some work in javascript based on the Id. But I dont want this Id to be visible on the grid. I tried to use the visible(false) property but that ended up not allowing me to use

row.cells[0].innerHTML since this gives the value of the first visible column. I also tried Hidden(true) which does allow me to get the Id but then my grid rows get out of sync with the column headings (the row aligned gets incorrect). Can you please point me in the the correct dirrection please

Tags
Grid
Asked by
Amitesh
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Amitesh
Top achievements
Rank 1
Share this question
or