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

Add div element dynamically in kendo grid template specific position

1 Answer 611 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Vikash asked on 05 Nov 2016, 06:36 AM

Hi All,

I am using kendo grid row template where i have to add dynamic div based on the text.

Below is my code:

<script id="altRowTemplate" type="text/x-kendo-tmpl">

    <tr class="k-alt" data-uid="#: uid #">

       <td style="width:100%">

                  <div class="col-sm-1">
                         <img src="@Url.Content("~/Content/Images/#: OwnerImage#")" class="img-responsive" style="width:80px; height:50px" alt="1" />

                   <div id="Category">






for the category in first row value is c# and second row value is: c#, Asp.Net, AngularJs

for change template below is the script function used.

function changeTemplate(category) {var splitCategory = category;var setCategorySpan = '';if (splitCategory.indexOf(',') !== -1) { splitCategory = category.split(',');for (var i = 0; i < splitCategory.length; i++) {var setcolID = 2;// Trim the excess whitespace. splitCategory[i] = splitCategory[i].replace(/^\s*/, "").replace(/\s*$/, "");// Add additional code here, such as: setCategorySpan += "<div class='col-sm-" + setcolID + "'><span class='tags' style='font-family:arial; font-size:small'>" + splitCategory[i] + "</span></div>"; setcolID+=2;} $("#dvCategory").append(setCategorySpan);}else { setCategorySpan = "<div class='col-sm-12'><span class='tags' style='font-family:arial; font-size:small'>" + splitCategory + "</span></div>"; $("#dvCategory").append(setCategorySpan);}}

in this function i am checking if value is seprated by comma then split one by one value and add in span tag and that tag should append in div.

i have checked through debug if i am directly appending value to div so this div is no more there, for that purpose i am creating this div in document ready function only:

var container = document.createElement('div'); container.setAttribute('id', 'dvCategory'); container.setAttribute('class', 'row');

if i am using here $('body').append(container);

value is showing but out of grid.

can i get help to set div on the same position where category is there?

1 Answer, 1 is accepted

Sort by
Alex Hajigeorgieva
Telerik team
answered on 08 Nov 2016, 02:24 PM
Hi Vikash,

I suggest placing the condition inside the template. You will need to escape any code blocks with hash literals as documented at:

I have created a sample Dojo runnable snippet to illustrate:

Kind Regards,
Alex Hajigeorgieva
Telerik by Progress
Build rich, delightful, *native* Angular 2 apps with Kendo UI for Angular 2. Try it out today! Kendo UI for Angular 2 (currently in beta) is a jQuery-free toolset, written in TypeScript, designed from the ground up to offer true, native Angular 2 components.
Asked by
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Share this question