Actually, I had the same problem. The way I handle this problem is as follows:
function listItemTemplateRenderer(item) { //Get data from item. var data = item._value.data; // if it is a special item renderer, apply special template if (data.isSpecialItem) { return specialItemRenderer(data); } var itemElement = document.createElement('div'); itemElement.className = "listItemTemplate"; var placeHolder = document.createElement('div'); placeHolder.className = "itemTemplateClass"; placeHolder.id = data.id; var itemDetail = document.createElement('div'); itemDetail.className = "itemDetailStyle"; ... //whatever you wanna add to your template //Append child elements placeHolder.appendChild(itemDetail); itemElement.appendChild(placeHolder); return { element: itemElement }; } // Template for the special item function messageItemRenderer(item) { var itemElement = document.createElement('div'); itemElement.className = "listItemTemplat"; var placeHolder = document.createElement('div'); placeHolder.className = "specialItemTemplate"; placeHolder.id = item.id; var dataText = document.createElement('div'); dataText.className = "dataText"; dataText.innerText = item.text; placeHolder.appendChild(dataText); itemElement.appendChild(placeHolder); itemElement.onclick = item.clickHandler; return { element: itemElement }; }
Hope this helps.
source share