Search results

Content

A text or a piece of information assigned to the Tooltip’s content property will be displayed as the main text stream of the Tooltip. It can be a string or a template content. If the content property is not provided with any specific value, then it takes the value assigned to the title attribute of the target element on which the Tooltip was initialized. The content can also dynamically be assigned to the Tooltip via AJAX.

Template content

Any text or image can be added to the Tooltip, by default. To customize the Tooltip layout or to create your own visualized element on the Tooltip, template can be used.

Refer to the following code example to add formatted HTML content to the Tooltip.

tagHelper
template.cs
@section ControlsSection{
    <ejs-tooltip id="tooltipContent" target="#target" content="<div><p><strong>Environmentally friendly</strong> or <strong>environment-friendly</strong>, <i>(also referred to as eco-friendly, nature-friendly, and green)</i> are marketing and sustainability terms referring to goods and services, laws, guidelines and policies that inflict reduced, minimal, or no harm upon ecosystems or the environment.</p></div>">
        <e-content-template>
            <div id='container'>
                <p>
                    A green home is a type of house designed to be
                    <a id="target">
                        <u>environmentally friendly</u>
                    </a> and sustainable. And also focuses on the efficient use of "energy, water, and building materials." As green homes
                    have become more prevalent we have also seen the emergence of green affordable housing.
                </p>
            </div>
        </e-content-template>
    </ejs-tooltip>
}
public ActionResult Template()
{
    return View();
}

Output be like the below.

ASP .NET Core - Tooltip - Content

Dynamic content via AJAX

The Tooltip content can be dynamically loaded by making use of the AJAX call. The AJAX request is usually made within the beforeRender event of the Tooltip, and then the Tooltip’s content is assigned the value retrieved on it’s success.

tagHelper
ajaxcontent.cs
@section ControlsSection{
    <div id='container'>
        <h4 class="list-header">National Sports</h4>
        <!-- Tooltip element rendering for AjaxContent loading -->
        <ejs-tooltip id="Tooltip" content="Loading..." beforeRender="onBeforeRender" target="#countrylist [title]" showTipPointer="true" position="RightCenter">
            <e-content-template>
                <!-- ListView element -->
                <ejs-listview id="countrylist" dataSource="ViewBag.data" enable="true">
                    <e-listview-fieldsettings text="text" tooltip="id"></e-listview-fieldsettings>
                </ejs-listview>
            </e-content-template>
        </ejs-tooltip>
    </div>
}

<script>
        /**
         * Process tooltip ajax content.
         */
  function onBeforeRender(args) {
            var _this = this;
            this.content = 'Loading...';
            this.dataBind();
            var ajax = new ej.base.Ajax("@Url.Content("~/Scripts/tooltip/tooltipdata.json")", 'GET', true);
            ajax.send().then(function (result) {
            result = JSON.parse(result);
            for (var i = 0; i < result.length; i++) {
                if (result[i].Id === args.target.getAttribute('data-content')) {
                    _this.content = "<div class='contentWrap'><span class=" + result[i].Class + "></span><div class='def'>" + result[i].Sports + "</div></div>";
                }
            }
            _this.dataBind();
        }, function (reason) {
            _this.content = reason.message;
            _this.dataBind();
        });
    }
</script>
<link href="~/css/tooltip/icons.css" rel="stylesheet" />
<style>

    .e-bigger [class^="sports-icon-"],
    .e-bigger [class*=" sports-icon-"] {
        font-size: 18px;
    }

    [class^="sports-icon-"],
    [class*=" sports-icon-"] {
        font-family: 'sportsicons';
        speak: none;
        font-size: 16px;
        font-style: normal;
        font-weight: normal;
        font-variant: normal;
        text-transform: none;
        padding-right: 6px;
        vertical-align: middle;
    }

    .sports-icon-cricket:before {
        content: "\e703";
    }

    .sports-icon-archery:before {
        content: "\e705";
    }

    .sports-icon-table-tennis:before {
        content: "\e702";
    }

    .sports-icon-baseball:before {
        content: "\e706";
    }

    .sports-icon-hockey:before {
        content: "\e701";
    }

    .sports-icon-shooting:before {
        content: "\e700";
    }

    .def {
        float: right;
    }

    #countrylist {
        border: 1px solid #dddddd;
        border-radius: 3px;
        max-width: 170px;
        margin: 0 auto;
        overflow: hidden;
    }

    .list-header {
        text-align: center;
        color: rgba(0, 0, 0, 0.54);
    }

    @@media (max-width: 481px) {
        #countrylist {
            margin: 0;
        }

        .list-header {
            text-align: left;
        }
    }
</style>
public ActionResult AjaxContent()
        {
             List<object> country = new List<object>();
            country.Add(new  { id = "1", text = "Australia" });
            country.Add(new  { id = "2", text = "Bhutan" });
            country.Add(new  { id = "3", text = "China" });
            country.Add(new  { id = "4", text = "Cuba" });
            country.Add(new  { id = "5", text = "India" });
            country.Add(new  { id = "6", text = "Switzerland" });
            country.Add(new  { id = "7", text = "United States" });
            ViewBag.data = country;
            return View();

        }

Output be like the below.

ASP .NET Core - Tooltip - Dynamic Content via Ajax