Articles in this section
Category / Section

How to customize the tooltip for custom toolbar item element in JavaScript Grid?

4 mins read

By default, the templateID property value of toolbarSettings->customToolbarItems (For Ex: Refresh) is shown as tooltip for custom toolbar item. So this Knowledge Base explains the way to define the custom tooltip for Custom Toolbar item in JavaScript Grid.

 HTML

                   <div id="Grid"></div>         

JS

<script type="text/javascript">
        $(function () {
            $("#Grid").ejGrid({
                // the datasource "window.gridData" is referred from jsondata.min.js
                dataSource: window.gridData,
                allowPaging: true,
                toolbarSettings: { showToolbar: true, customToolbarItems: [{ templateID: "#Refresh" }] },
                columns: [
                         { field: "OrderID", headerText: "Order ID", isPrimaryKey: true, width: 90 },
                         { field: "CustomerID", headerText: "Customer ID", width: 90 },
                         { field: "EmployeeID", headerText: "Employee ID",  width: 90 },
                         { field: "Freight", headerText: "Freight",width: 90, format: "{0:C}" },
                         { field: "ShipCity", headerText: "Ship City", width: 90 }
                ],
                dataBound: "databound"
            });
        });
</script>

 

Razor

@(Html.EJ().Grid<MVCSampleBrowser.Models.EditableOrder>("Grid")
        .Datasource((IEnumerable<object>)ViewBag.datasource)
        .AllowPaging()
        .Columns(col =>
            {
                col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).Width(90).Add();
                col.Field("CustomerID").HeaderText("Customer ID").Width(90).Add();
                col.Field("EmployeeID").HeaderText("EmployeeID").Width(90).Add();
                col.Field("Freight").HeaderText("Freight").Format("{0:C}").Width(90).Add();
                col.Field("ShipCity").HeaderText("Ship City").Width(90).Add();
            })
          .ClientSideEvents(eve => eve.DataBound("databound"))
          .ToolbarSettings(tool => tool.ShowToolbar().CustomToolbarItems(new List<object>() {
            new Syncfusion.JavaScript.Models.CustomToolbarItem() { TemplateID = "#Refresh" }
            }))
)

 

C#

namespace Sample.Controllers
{
    public class GridController : Controller
    {
      public ActionResult GridFeatures()
        {
            var DataSource = new NorthwindDataContext().OrdersViews.ToList();
            ViewBag.datasource = DataSource;
            return View();
        }
    }
}

 

ASPX

<ej:Grid ID="Grid" runat="server" AllowPaging="True">
        <ToolbarSettings ShowToolbar="true">
            <CustomToolbarItem>
                <ej:CustomToolbarItem TemplateID="#Refresh" />
            </CustomToolbarItem>
        </ToolbarSettings>
        <Columns>
            <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" Width="90"></ej:Column>
            <ej:Column Field="CustomerID" HeaderText="CustomerID" TextAlign="Left" Width="90" />
            <ej:Column Field="EmployeeID" HeaderText="EmployeeID" Width="90"></ej:Column>
            <ej:Column Field="Freight" HeaderText="Freight" Format="{0:C}" Width="90"></ej:Column>
            <ej:Column Field="ShipCity" HeaderText="ShipCity" Width="90" />
        </Columns>
        <ClientSideEvents DataBound="databound" />
    </ej:Grid>

 

Adding custom icons to the Toolbar

Js Render

<script id="Refresh" type="text/x-jsrender">
        <a class="e-toolbaricons e-icon refresh" />
    </script>

A custom icon Refresh is added to the Toolbar and style is applied to it.

CSS

<style type="text/css" class="cssStyles">
        .refresh:before {
            content: "\e677";
        }
</style>

 

In dataBound event of grid, define your own custom tooltip for the corresponding custom toolbar item by using data-contentattribute of the particular element.

<script>
        function databound(args) {
            $("#" + this._id + "_Refresh").attr("data-content", "click to refresh");  //Here Refresh is the templateID value. Define your own custome tooltip value to the data-content attribute for the particular element.
        }
    </script>

 

C:\Users\Manisankar.durai\Desktop\custom icon tooltip.png

Figure: Shows custom tooltip for the custom toolbar item.


Conclusion

I hope you enjoyed learning about how to customize the tooltip for custom toolbar item element in Grid.

You can refer to our JavaScript Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.  You can also explore our  JavaScript Grid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied