2

When placing a Telerik RadHtmlChart inside a Knockout foreach template, I encounter "Uncaught TypeError: Cannot set property 'control' of undefined" JavaScript error, but only if I include runat="server" (which I'd like to include since I want my C# codebehind to configure the control).

<tbody data-bind="foreach: Measures">
    <td class="trendCell">
        <div class="sparklineWrapper">
            <telerik:RadHtmlChart data-bind="attr: { id: 'sparkline_' + $index }" runat="server" Layout="Sparkline" class="sparkline" />
        </div>
    </td>
    ...

Bottom line: how to include a Telerik RadHtmlChart inside a Knockout foreach template while still enabling codebehind access?

Thanks for your time.

Troy S.

p.s. Databinding the templated control is a whole other story which I have yet to tackle. I have previously placed 14 RadHtmlChart controls (each with a unique, static ID) onto a page and manually databound them each time a web api AJAX call is made, but I expect the templated control to be challenging.

RESOLUTION:

After a few hours of experimenting, I have successfully used the client-side (duh!) Kendo sparkline control inside the Knockout foreach template (instead of bashing my head against the wall by trying to use the server-side Telerik sparkline control). Works like a charm.

<div class="sparkline" data-bind="attr: { id: 'sparkline_' + $index() }"></div>
...
for (var i = 0; i < self.Items().length; i++) {
    // convert comma-delimited trend string into an int[] array
    var data = [ ];
    data.push.apply(data, self.Items([i].TrendData().split(",").map(Number));

    var id = "#sparkline_" + i;
    $(id).kendoSparkline(data);
}
  • knockout is a client side library. Other than using the codebehind to write the data to the page and rendering telerik afterwords on the local data, I'm not sure how this would work. – CtrlDot Feb 27 '14 at 18:32
  • You can't mix a server control with a clientside library like knockout in this example. If you really stuck with using Telerik you will have to use the Kendo – Robert Slaney Feb 27 '14 at 21:31
  • @RobertSlaney (and CtrlDot): Thanks! It makes perfect sense...NOW. I have begun the task of using the Kendo sparkline control on the page. It doesn't seem to like knockout templates either but I'm sure I'll get there if it is possible. p.s. I changed my SO name and now my stats are gone--weird. – Troy Scheffel Feb 28 '14 at 16:53

0 Answers0