Bound data type is changing

2 posts, 0 answers
  1. Courtney
    Courtney avatar
    13 posts
    Member since:
    Apr 2007

    Posted 11 Jul 2014 Link to this post

    I am using a RadHtmlChart that calls a javascript method when a series is clicked:

    <telerik:RadHtmlChart runat="server" ID="SBarChart1" Transitions="false" EnableTheming="true" CssClass="Chart"
                        OnClientSeriesClicked="OnBarClientSeriesClicked" > ...

    The chart is bound to a DataTable.  The first row in the table has the data:

    - resultsTbl.Rows[0].ItemArray {object[5]} object[]
    [0] "Jan '13" object {string}
    [1] "012013" object {string}
    [2] 5510.83 object {decimal}
    [3] 0 object {decimal}
    [4] 0 object {decimal}

    As you can see the second item is a STRING with a value of "012013".  The column name for this field is "CategoryID.  Take note of the leading zero in the string!

    When a user clicks on a chart series, the Javascript OnClientSeriesClicked method is called and I retrieve the data from the series using the args.get_dataitem() method:

    function BarClientSeriesClicked(sender, args) {
        var theDataItem = args.get_dataItem();

    The data I get back in the VAR theDataItem is:
    CategoryText   "Jan '13"
    CategoryID      12013
    Domestic          5510.83
    International      0

    As you can see the Type of the CategoryID field has changed from STRING to an INTEGER (the value is no longer quoted). A side effect of this TYPE change is that my string value has changed (the leading zero has been removed)! Somewhere after the databind of the chart to the DataTable, and before the Javascript method call occurs, something is reinterpreting my STRING field as an INTEGER and changing the type.  

    I want my bound STRING fields to remain as STRING types when I retrieve the data in the Javascript BarClientSeriesClicked method.  A side effect of changing the field type is the leading zero is truncated and my string comparison no longer works (my later code is expecting a string containing a two-digit month and four digit year which is no longer the case).

    I believe this is a bug somewhere deep in the RadHtmlChart code.  As you can see I am binding a STRING field to the chart and I have nothing else to do with the data until the chart calls the OnClientSeriesClickedEvent where the data type has magically changed.

    I have a work around where I can force a non-numeric character at the start of my string (e.g. prepend the letter 'a' to my original CategoryID value, e.g. 'a012013'). After I get the data value with args.get_dataItem(), my value remains as a STRING type (as you can see the value is now quoted indicating it is a STRING type):

    CategoryText   "Jan '13"
    CategoryID      "a012013"
    Domestic          5510.83
    International      0

    I can then strip off the leading 'a' character and I have a CategoryID of type STRING that is properly formatted with my leading zero intact.

    Even though I have a work around I am bringing this up because it seems to be a bug somewhere in the RadHtmlChart code.



  2. Danail Vasilev
    Danail Vasilev avatar
    1502 posts

    Posted 15 Jul 2014 Link to this post

    Hi Courtney,

    This is a known issue with the control that has already been logged in our feedback portal here. You can monitor its progress, put your comments below or raise its priority by voting on it. For the time being you can proceed with the current workaround.

    Danail Vasilev

    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.

Back to Top