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

Grid conditional column bound

1 Answer 1103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hüseyin altun
Top achievements
Rank 1
hüseyin altun asked on 19 Aug 2013, 02:02 PM
Hi, 

Code block is below.
I want to show value conditionally and i can not edit model block .

is there a way to do this.
i know it's not working like i do .
@(Html.Kendo().Grid(Model)
   .Name("somegrid")
   .Columns(columns =>
   {
       columns.Bound(Folder => Folder.ParentId).Template(@<text>
 <strong>@if (item.ParentId > 0)
         {
     <span>@callfunction(item.Name)   (call some serverside function using item variable which returns string ( but not parentId another one ) )</span>
         }
         else
         {
     <span>@call some serverside function</span>
         }
 </strong>
 </text>); 
       columns.Command(command => { command.Edit().Text("Güncelle").UpdateText("Güncelle").CancelText("İptal"); command.Destroy().Text("Sil"); }).Width(180);
 
   })
                .ToolBar(toolbar => toolbar.Create().Text("Yeni kayit ekle"))
                .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("FolderEditPopup").DisplayDeleteConfirmation("Kaydı silmek istediğinizden emin misiniz ?"))
                .Pageable(pager => pager
                .Messages(messages => messages.Display("{0} - {1}. Toplam {2} kayıt")
                                          .ItemsPerPage("")
                                          .First("İlk sayfa")
                                          .Last("Son sayfa")
                                          .Next("Sonraki")
                                          .Page("Sayfa")
                                          .Previous("Önceki")
                                          .Refresh("Yenile"))
               )
               .Sortable()
               .Scrollable()
               .Events(e => e.Edit("onEdit"))
               .DataSource(dataSource => dataSource
                   .Ajax()
                   .PageSize(100000)
                   .Model(model =>
                   {
                       model.Id(p => p.IntId);
                       model.Field(p => p.ParentId).DefaultValue(0);
                   })
                   .Events(events => events.Error("error_handler"))
                   .Create(update => update.Action("FolderPopup_Create", "Config"))
                   .Read(read => read.Action("FolderPopup_Read", "Config"))
                   .Update(update => update.Action("FolderPopup_Update", "Config"))
                   .Destroy(update => update.Action("FolderPopup_Destroy", "Config"))
               )
           )


Thanks for help

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander Popov
Telerik team
answered on 21 Aug 2013, 11:44 AM
Hi Hüseyin,


I'm not sure that I understand you correctly, however after reviewing the provided code I noticed the following:

  1. The Model is passed to the Grid helper, meaning that the initial data is rendered server side and the Template method is used.
  2. The Grid uses Ajax binding meaning additional requests are rendered client side and ClientTemplate method is used.
Here is an example demonstrating similar behavior using client templates (in current case you should set both the Template and the ClientTemplate):

  • Define the ClientTemplate:    
  • columns.Bound(Folder => Folder.ParentId
    ).ClientTemplate(
    "#=generateTemplate(data)#");
  • Define the generateTemplate function:    
    <script type="text/javascript">
        function generateTemplate(item)
        {
            var template = "<strong><span>";
     
            if(item.ParentId > 0)
            {
                template = template + callFunction(item.Name);
            }
            else
            {
                template = template + callOtherFunction(item.Name);
            }
            template = template + "</span></strong>";
             
            return template;
        };
    </script>

Also I would suggest checking the KendoUI template documentation.

In case the above example doesn't answer your question, please provide additional information so we can advice you further.

Kind Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
hüseyin altun
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or