I want to realize a scenario where Html-Attributes are conditionally applied to cells. In a ClientTemplate it would look like
" #if(BooleanProperty) { <p style=\"MyStyle: MyValue\">#= ValueProperty #</p> } else { <p>#=ValueProperty#</p> } "
My Questions now:
1. Is this possible without using a client template?
2. How exactly must the syntax look like?
I hope you can help me...
brgds
Malcolm
7 Answers, 1 is accepted
Using a client template with conditional logic inside is the correct way to go in the current case.
Regards,
Dimiter Madjarov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
I have a ForeignKey column that I would rather not create a ClientTemplate for, but would like to conditionally set an html attribute
static: HtmlAttribute( new{ @class = "specialClass" } );
desired pseudo-code...
conditional: HtmlAttribute( "#if (IsSpecial) {# new{ @class = 'specialClass' } #}#");
Is there any way to accomplish conditional HtmlAttributes without using a client template?
Thanks,
Will
Hello Will,
HtmlAttributes is a server method and is rendered on the server side. This is why a client template cannot be used inside, because the data is read on the client side via Ajax.
Regards,Dimiter Madjarov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
Hello Curt,
The reason is described in my previous post. HtmlAttributes is a server method and is rendered on the server side, while the data is bound later on the client side via Ajax.
Regards,Dimiter Madjarov
Telerik
Hi Sven,
In order to achieve the desired behavior, use a function handler in the HtmlAttributes.
In the function handler return the desired content.
Here is an example:
// column configuration
columns.Bound(p => p.OrderDate).HtmlAttributes("attributesHandler");
//handler
function attributesHandler(data) {
return { title: `Order Date: ${kendo.toString(data.OrderDate, 'dd-MM-yyyy')} ` }
}
Give a try to the approach above and let me know if further assistance or information is needed.
Kind Regards,
Anton Mironov
Thank you for your answer,
but despite your efforts I was able to solve it using ClientTemplate ^^. Our ClientTemplate checked the data-value for the column and surrounded the field with a <span> Element .. I simply sourrounded the span with a div that received a css class and here I was able to apply the behaviour I was after. (height, background-colour, margin and so on)
Hi Sven,
Thank you for sharing your approach with the community.
If further assistance or information is needed, do not hesitate to contact me and the team.
Best Regards,
Anton Mironov