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

Conditional HTML Properties - How to realize?

7 Answers 1417 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Malcolm
Top achievements
Rank 1
Malcolm asked on 18 Jun 2014, 02:32 PM
Hello Dear Telerik Team!

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

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 18 Jun 2014, 03:28 PM
Hello Malcolm,


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.

 
0
Will
Top achievements
Rank 1
answered on 10 Mar 2015, 10:49 PM
Hi Dimiter,

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

0
Dimiter Madjarov
Telerik team
answered on 11 Mar 2015, 08:53 AM

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.

 
0
Curt Rabon
Top achievements
Rank 1
Veteran
answered on 16 Jun 2015, 07:56 PM
Why couldn't you allow us to pass a lambda to .HtmlAttributes() that allowed us to specify the attributes based on the value of one of the model properties?
0
Dimiter Madjarov
Telerik team
answered on 17 Jun 2015, 10:39 AM

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
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 Feedback Portal and vote to affect the priority of the items
0
Sven
Top achievements
Rank 1
Iron
Iron
Iron
answered on 15 Jun 2023, 12:45 PM
Then please elaborate how I affect the "whole" cell like I could achieve using jquery addClass-method by using the .ClientTemplate which creates in my case a span with class to replace checkbox with an arrow 
Anton Mironov
Telerik team
commented on 19 Jun 2023, 05:44 AM

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

0
Sven
Top achievements
Rank 1
Iron
Iron
Iron
answered on 19 Jun 2023, 09:09 AM

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)

Anton Mironov
Telerik team
commented on 21 Jun 2023, 06:49 AM

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

Tags
Grid
Asked by
Malcolm
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Will
Top achievements
Rank 1
Curt Rabon
Top achievements
Rank 1
Veteran
Sven
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or