Missed JavaScript Days 2026? The Replays Are Now Available – Watch Now!

How to Quickly Customize Ext JS Data Grid (Part 6/6) – Adding Custom CSS Class to Grid Elements

April 3, 2020 6113 Views

Get a summary of this article:

Show

In this concluding blog of our 6-part blog series on “Customizing Your Ext JS Grid”, we talk about using built-in properties to add custom CSS class to grid elements.

There are multiple ways to add custom CSS class to elements. Let’s discuss a few and how to use them.

Using built-in properties

Grid configuration:

  • baseCls
  • cls
  • componentCls
  • bodyStyle
  • style
  • ui

Column:

  • tdCls

1. Define the class to add in column configuration:

{
        dataIndex: 'player',
        flex: 1,
        text: 'Name',
        //CSS class to add
        tdCls: 'player'
}

2. Create CSS class :

.player {
   font-weight: bold;
}

Sencha Fiddle:

Using built-in methods

With renderer method it is possible to access a collection of metadata of the current cell and customize data display.
Override renderer method in column configuration :

      {
        dataIndex: 'team',
        text: 'Team',
        flex:1,
        //Use metadata to modify background color
        renderer: function (value, metaData) {
          metaData.tdAttr = 'bgcolor="grey"';
          return value;
      }

Override getRowClass template function

Override this function to apply custom CSS classes to rows during rendering
1. Override method in grid configuration :

viewConfig: {
        getRowClass: function(record, rowIndex, rowParams, store){
            return record.get("rating") > 86 ? "superstar" : "";
        }
    }

2. Create CSS class :

.superstar {
   color: red;
}

Sencha Fiddle:

Use theme variables

Ext JS is equipped with a large selection of theme variables to enhance the data grid.
Read more about theme variables in the documentation here.

With Ext JS, you have enormous flexibility to make your grid appear the way you want it to!
I hope you’ve enjoyed this series on customizing Data Grids. If you missed the previous articles, here’s a quick recap of all posts from this 6-part blog series.
 
Customize using built-in grid and column properties
Customize using grouping methods
Customize using row editing methods
Customize grid display data
Customize using widget column methods
Customize with custom CSS class

It doesn’t end here. Check out our extensive product documentation packed with working examples on everything grid. Looking for something that wasn’t covered here? Connect with us through our forum and get answers to all your pressing questions.

 

Build Your Data Grid with Ext JS 7.1

The free 30-day trial of Ext JS 7.1 provides full access to the product features. Get started today and see how you can build a high-performing data grid for your application.

Author

Kirti Joshi

Kirti Joshi is long time techie and has worked at a number of companies delivering cutting-edge hardware and software products. She currently works as a Product Marketing Manager at Sencha and is passionate about technology products that improve human life.

Recommended Articles

How to Use the Ext JS Grid in React: Setup, Columns, Editing and Grouping

Set up the Ext JS grid in React with ReExt, then add typed columns, store-backed data, inline editing, grouping and summaries. Full code included. The…

Understanding Ext JS Layouts and Containers: An Introduction (Classic vs. Modern)

Building complex, responsive, and data-intensive Web applications requires a solid layout engine. In Ext JS, the layout system is the backbone of your Application UI.…

AI-Driven Test Grading with Ext JS, Node.js, and OpenAI: A Secure Enterprise Architecture

Learn how to build an AI-driven test grading system with Ext JS, Node.js, MySQL, and OpenAI using secure API architecture, deterministic scoring, and human oversight.…

Sencha AI Just Got a Lot Bigger: One Chatbot, Every Sencha Product

Sencha’s AI assistant has grown from a focused Ext JS helper into a product-aware chatbot covering the whole Sencha suite. Here’s what’s new and why…

Building High-Performance Real-Time Operational Dashboards with Ext JS and React

Real-time operational dashboards are no longer simply reporting interfaces. In logistics, fleet management, supply chain operations, financial services, and other data-intensive environments, they are part…

Async/await with Ext JS

Probably one of the most appreciated features of the latest versions of JavaScript is Promises, and in particular their use through the new language keywords…

View More