0

I am trying to use custom data attribute

<span class="k-nav-day" data-dt="kendo.toString(date, 'dd/MM/yyyy')">

</span>

But when i try below code in JavaScript,

  var dateOfHeader = $(this).data("dt"); 

It still gives me in quotes and its not getting evaluated

  "kendo.toString(date, 'dd/MM/yyyy')"

It should have formatted the 'date' and date should be assigned to variable "dateOfHeader" = 27/05/2015

Note: I do not have any error in console

Background on Question

I am using scheduler control and I need to render some color based on dates. my data source is having JSON as follow

 var mydatafromApi = ({
   date:01/01/2013, 
   percentage=30%,
   color = red
  },
 {
   date:02/01/2013, 
   percentage=40%
   color = blue
 });

Now I need to compare every date of scheduler/calendar and display background based on this JSON data

So while rendering I am storing date in custom data attribute, but to read it back I am facing issues.

kudlatiger
  • 3,028
  • 8
  • 48
  • 98

2 Answers2

0

In this specific case you can use javascript eval function

var dateOfHeader = eval($(this).data("dt"));
Mladen Oršolić
  • 1,352
  • 3
  • 23
  • 43
  • Thanks Mladen. But while evaluating it says "date is not defined" - The background of problem is here : http://stackoverflow.com/questions/30308682/rendering-data-in-kendo-scheduler-control-header-dateheadertemplate/30320045#30320045 – kudlatiger May 26 '15 at 09:39
  • ohh, well your date variable should be replaced with actual value within single quotes `"kendo.toString('01/01/2013', 'dd/MM/yyyy')"` – Mladen Oršolić May 26 '15 at 09:53
0

When you call a javascript function to be rendered with its evaluated data in html, you need to wrap your function with #= # expression

data-dt="#= kendo.toString(date, 'dd/MM/yyyy') #"

You should be able to get the data using jQuery data

$(element).data("dt");
Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
Dion Dirza
  • 2,575
  • 2
  • 17
  • 21