Articles in this section
Category / Section

How to place icons in command column buttons instead of text in ASP.NET MVC Grid?

3 mins read

In command column buttons by default, the text such as Edit/Delete/Save/Cancel will be displayed. We can also place the icons in those buttons.

Let us see how to place icons in command column buttons.

Grid Initialization

JS

 
$("#Grid").ejGrid({
            dataSource: window.employeeView,
            allowPaging: true,
            allowSelection: false,
            enableRowHover: false,
            editSettings:{ allowEditing:true, allowDeleting:true },
            columns: [               
                      { field: "EmployeeID", headerText: 'Employee ID', isPrimaryKey:true },
                      { field: "FirstName", headerText: 'First Name'},
                      { field: "LastName", headerText: 'Last Name'},
                      {
                          headerText: "Manage Records",
                          commands: [
                              { type: ej.Grid.UnboundType.Edit, buttonOptions: { contentType: "imageonly", prefixIcon:"e-icon e-edit" } },
                              { type: ej.Grid.UnboundType.Delete, buttonOptions: { contentType: "imageonly", prefixIcon: "e-icon e-delete" } },
                              { type: ej.Grid.UnboundType.Save, buttonOptions: { contentType: "imageonly", prefixIcon: " e-icon e-save" } },
                              { type: ej.Grid.UnboundType.Cancel, buttonOptions: { contentType: "imageonly", prefixIcon: " e-icon e-cancel" } }
                          ],
                          isUnbound: true
                      }
            ]       
        });
 

 

MVC

 
@(Html.EJ().Grid<object>("Grid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.AllowPaging()
    .EditSettings(e => e.AllowEditing().AllowDeleting())
    .Columns(col =>
    {
 
            col.Field("EmployeeID").HeaderText("Employee ID").IsPrimaryKey(true).Add();
            col.Field("FirstName").HeaderText("First Name").Add();
            col.Field("LasttName").HeaderText("Last Name").Add();
            col.HeaderText("Manage Records").IsUnbound(true).Commands(commands =>
            {
                commands.Type(UnboundType.Edit).ButtonOptions(new ButtonProperties()
                {
                    ContentType = ContentType.ImageOnly,
                    PrefixIcon = "e-icon e-edit"
                }).Add();
                commands.Type(UnboundType.Delete).ButtonOptions(new ButtonProperties()
                {
                    ContentType = ContentType.ImageOnly,
                    PrefixIcon = "e-icon e-delete"
                }).Add();
                commands.Type(UnboundType.Save).ButtonOptions(new ButtonProperties()
                {
                    ContentType = ContentType.ImageOnly,
                    PrefixIcon = "e-icon e-save"
                }).Add();
                commands.Type(UnboundType.Cancel).ButtonOptions(new ButtonProperties()
                {
                    ContentType = ContentType.ImageOnly,
                    PrefixIcon = "e-icon e-cancel"
                }).Add();
            }).Width(75).Add();
        }))
 

 

ASPX

 
<ej:Grid ID="Grid" runat="server" AllowPaging="true" AllowSelection="false" EnableRowHover="false">           
            <Columns>
                <ej:Column Field="EmployeeID" HeaderText="Employee ID" IsPrimaryKey="true"/>
                <ej:Column Field="FirstName" HeaderText="First Name"/>
                <ej:Column Field="LastName" HeaderText="Last Name"/>
                <ej:Column HeaderText="Manager Recors">
                    <Commands>
                        <ej:Commands Type="edit">
                            <ButtonOptions ContentType ="ImageOnly" PrefixIcon="e-icon e-edit" />
                        </ej:Commands>
                        <ej:Commands Type="delete">
                            <ButtonOptions ContentType ="ImageOnly" PrefixIcon="e-icon e-delete" />
                        </ej:Commands>
                        <ej:Commands Type="save">
                            <ButtonOptions ContentType ="ImageOnly" PrefixIcon="e-icon e-save" />
                        </ej:Commands>
                        <ej:Commands Type="cancel">
                            <ButtonOptions ContentType ="ImageOnly" PrefixIcon="e-icon e-cancel" />
                        </ej:Commands>
                    </Commands>
                </ej:Column>
            </Columns>
        </ej:Grid>
 

 

The result will be as follows.

Command column with icon before editing in ASP.NET MVC Grid

Figure 1: Command column with icon before editing

 

Command column with icon after editing in ASP.NET MVC Grid

Figure 2: Command column with icon after editing

Using custom icons

The icons showed in the above examples are available in the Syncfusion`s default theme packages. We can also use our own custom icons in the command buttons.

For example, to use the Font-Awesome icons in the command button, include the reference to the Font-Awesome icons CSS file in your page.

 
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
 

 

And then specify the corresponding icon class in the prefixIcons property of the buttonOptions.

$("#Grid").ejGrid({
            dataSource: window.employeeView,
            allowPaging: true,
            allowSelection: false,
            enableRowHover: false,
            editSettings: { allowEditing: true, allowDeleting: true },
            columns: [
                      { field: "EmployeeID", headerText: 'Employee ID', isPrimaryKey: true },
                      { field: "FirstName", headerText: 'First Name' },
                      { field: "LastName", headerText: 'Last Name' },
                      {
                          headerText: "Manage Records",
                          commands: [
                              { type: ej.Grid.UnboundType.Edit, buttonOptions: { contentType: "imageonly", prefixIcon: "fa fa-pencil-square-o" } },
                              { type: ej.Grid.UnboundType.Delete, buttonOptions: { contentType: "imageonly", prefixIcon: "fa fa-times" } },
                              { type: ej.Grid.UnboundType.Save, buttonOptions: { contentType: "imageonly", prefixIcon: "fa fa-floppy-o" } },
                              { type: ej.Grid.UnboundType.Cancel, buttonOptions: { contentType: "imageonly", prefixIcon: "fa fa-times" } }
                          ],
                          isUnbound: true
                      }
            ]
        });
 

 

In such a way, you can assign the CSS class of the corresponding icon in the PrefixIcons property of the ASP.Net MVC Grid and ASP.Net Grid to show the icons in the custom button.

The output result is as follows.

Grid with custom icon in command button before edit in ASP.NET MVC Grid

Figure 3: Grid with custom icon in command button before edit

Grid with custom icon in command button after edit in ASP.NET MVC Grid

Figure 4: Grid with custom icon in command button after edit

 

Conclusion

I hope you enjoyed learning about how to place icons in command column buttons instead of text in ASP.NET MVC Grid.

You can refer to our ASP.NET MVC 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 ASP.NET MVC 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 (0)
Please sign in to leave a comment
Access denied
Access denied