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

Contenating String in Ternary Expression inside ClientTemplate

1 Answer 173 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karthikeyan
Top achievements
Rank 1
Karthikeyan asked on 22 Apr 2014, 09:00 PM
Hi,

I have a grid with date column. If the date value is greater than 30 then i want to display the date value as is otherwise display the difference in days like "In x Days".

I able to display formatted date value or difference in days correctly using the below code.

div class="col-md-12" id="recurringPaymentList">
@(Html.Kendo().Grid<PaymentsModel>()
.Name("scheduledPayment")
.Columns(columns =>
{
columns.Bound(c => c.NextPaymentDate).ClientTemplate(
"#= ( Math.round((NextPaymentDate - new Date())/1000/60/60/24 ))>30 ? kendo.toString(NextPaymentDate, 'MM/dd/yyyy') : kendo.toString(Math.round((NextPaymentDate - new Date())/1000/60/60/24 )) #"
);

However, when i try to contenate string values (see code below) in the ternary expression grid data does not bind and i dont see any error.

columns.Bound(c => c.NextPaymentDate).ClientTemplate(
"#= ( Math.round((NextPaymentDate - new Date())/1000/60/60/24 ))>30 ? kendo.toString(NextPaymentDate, 'MM/dd/yyyy') : 'In ' + kendo.toString(Math.round((NextPaymentDate - new Date())/1000/60/60/24 ))  " ' Day' #"
);

Is there any way to get the string contenate work in ternary expression or any other way of doing this?
 

1 Answer, 1 is accepted

Sort by
-1
Accepted
Dimiter Madjarov
Telerik team
answered on 24 Apr 2014, 12:09 PM
Hello Karthikeyan,


I see that my colleague Alexander has covered this issue in the support thread. Posting the support issues at one place only would help us to handle them faster.

Do not hesitate to contact us again if you experience further issues. I wish you a great day!

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Accedia
Top achievements
Rank 1
commented on 01 Dec 2021, 09:59 AM | edited

Would you post a link to the solution?
Anton Mironov
Telerik team
commented on 03 Dec 2021, 09:00 AM

Hi Accedia,

In order to achieve the desired behavior, I would recommend trying the following syntax for the case:
// Kendo UI Grid
columns.Bound(c => c.NextPaymentDate).ClientTemplate("#=calculateDate(NextPaymentDate)#");

//JavaSrcipt
<script>
function calculateDate(NextPaymentDate){
  ....
  return textToBeDisplayed;
}
 
</script>
Give a try to the approach above and let me know if further assistance is needed.

Kind Regards,
Anton Mironov
Tags
Grid
Asked by
Karthikeyan
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or