New to Kendo UI for jQuery? Download free 30-day trial

Use Grid Edit Buttons with Icons Only and No Text

Environment

Product Progress® Kendo UI® Grid for jQuery
Product Version 2017.2.504

Description

How can I use the Edit, Delete, Update, Cancel, and Add buttons only with icons and without displaying any text in them?

Solution

  1. Set command.text to a space.

        columns: [
          { command: [
            { name: "edit", text: { edit: " ", update: " ", cancel: " " } },
            { name: "destroy", text: " " }
          ] }
        ]
    
  2. Set toolbar.text to a space.

        toolbar: [{name: "create", text: " "}]
    
  3. In addition, reset some of the default margins of the buttons' icons to 0 (zero) by using CSS.

    Important

    The selectors in the CSS rules override the styles of the Kendo UI theme.

      .k-grid .k-grid-toolbar .k-grid-add,
      .k-grid tbody .k-grid-edit-command,
      .k-grid tbody .k-grid-save-command,
      .k-grid tbody .k-grid-cancel-command,
      .k-grid tbody .k-grid-remove-command {
        min-width: 0;
      }
    
      .k-grid .k-grid-toolbar .k-grid-add .k-icon,
      .k-grid tbody .k-grid-edit-command .k-icon,
      .k-grid tbody .k-grid-update .k-icon,
      .k-grid tbody .k-grid-cancel .k-icon,
      .k-grid tbody .k-grid-remove-command .k-icon {
        margin: 0;
      }
    

The following example demonstrates the full implementation of the suggested approach.

    <style>
      .k-grid .k-grid-toolbar .k-grid-add,
      .k-grid tbody .k-grid-edit-command,
      .k-grid tbody .k-grid-update,
      .k-grid tbody .k-grid-cancel,
      .k-grid tbody .k-grid-remove-command {
        min-width: 0;
      }

      .k-grid .k-grid-toolbar .k-grid-add .k-icon,
      .k-grid tbody .k-grid-edit-command .k-icon,
      .k-grid tbody .k-grid-update .k-icon,
      .k-grid tbody .k-grid-cancel .k-icon,
      .k-grid tbody .k-grid-remove-command .k-icon {
        margin: 0;
      }

    </style>
    <div id="example">
      <div id="grid"></div>

      <script>
        $(document).ready(function () {
          var crudServiceBaseUrl = "https://demos.telerik.com/kendo-ui/service",
              dataSource = new kendo.data.DataSource({
                transport: {
                  read:  {
                    url: crudServiceBaseUrl + "/Products",
                    dataType: "jsonp"
                  },
                  update: {
                    url: crudServiceBaseUrl + "/Products/Update",
                    dataType: "jsonp"
                  },
                  destroy: {
                    url: crudServiceBaseUrl + "/Products/Destroy",
                    dataType: "jsonp"
                  },
                  create: {
                    url: crudServiceBaseUrl + "/Products/Create",
                    dataType: "jsonp"
                  },
                  parameterMap: function(options, operation) {
                    if (operation !== "read" && options.models) {
                      return {models: kendo.stringify(options.models)};
                    }
                  }
                },
                batch: true,
                pageSize: 10,
                schema: {
                  model: {
                    id: "ProductID",
                    fields: {
                      ProductID: { editable: false, nullable: true },
                      ProductName: { validation: { required: true } }
                    }
                  }
                }
              });

          $("#grid").kendoGrid({
            dataSource: dataSource,
            pageable: true,
            height: 500,
            toolbar: [{name: "create", text: " "}],
            columns: [
              { field: "ProductName" },
              { command: [
                {name: "edit", text: { edit: " ", update: " ", cancel: " " }},
                { name: "destroy", text: " "}
              ], title: "&nbsp;", width: "250px" }
            ],
            editable: "inline"
          });
        });

      </script>
    </div>
In this article