Async tooltip using JSON and kendo.template

3 posts, 0 answers
  1. Caecilia
    Caecilia avatar
    3 posts
    Member since:
    Feb 2014

    Posted 25 Aug Link to this post

    Hi, currently I am doing the following to get some tooltip information on a grid row:

    $("#gridPop").kendoTooltip({
                    filter: 'td:nth-child(10)',
                    content: function (e) {
                        var template = kendo.template($("#myToolTipTemplate").html());
                        var dataItem = $("#grid").data("kendoGrid").dataItem(e.target.closest("tr"));
                        var tooltipHtml;
                        $.ajax({
                            url: DetailsURL + "/" + dataItem.Id,
                            async: false
                        }).done(function (data) {   // data is a JSON object from the server with details for the row
                            if (data.Success) {
                                data.Result = data.Result.replace(/null/g, "\"N/A\"");
                                tooltipHtml = template($.parseJSON(data.Result));
                            } else {
                                tooltipHtml = "Ooops!<br>Something went wrong (" + data.Result + ")";
                            }
                        });
                        return tooltipHtml;
                    }
                });

     

    I would like to get rid of the synchronous ajax call and make it asynchronous. I saw some asynchronous examples where the server delivers the full html, but nothing that works with JSON data from the server, that is then "compiled" via a kendo.template() to html on the client. Any suggestions how to do this?

  2. Ianko
    Admin
    Ianko avatar
    1741 posts

    Posted 29 Aug Link to this post

    Hello Caecilia,

    Using asynchronous calls should respect the way the content is injected to the tooltip. Using the content property as a function is a valid option, but as the content injected is the returned result of this function, makes it rather unsuitable for this scenario. In the showcased code, the tooltipHtml variable is returned before being altered by the asynchronous call. However, it is possible to make it work, you just need to inject the HTML you need to the content of the tooltip directly when the AJAX call is done. You can check out this example here: http://dojo.telerik.com/inewis/2

    Regards,
    Ianko
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Caecilia
    Caecilia avatar
    3 posts
    Member since:
    Feb 2014

    Posted 01 Sep Link to this post

    Thanks, Ianko! Life can be so easy when you know what you are doing...

Back to Top