1 min read

Ext JS Tip Of The Day: XTemplate Exceptions

If you ever worked with the Ext JS grid panel and put custom renderers on your columns, you may have […]

We strive to keep posts updated, but code samples may sometimes be outdated. Humans, see the Bryntum documentation; agents, https://mcp.bryntum.com for the latest info.

If you ever worked with the Ext JS grid panel and put custom renderers on your columns, you may have fought this issue before. Deep in the XTemplate class (which powers most visual components in Ext JS), there is an evil try/catch statement that silently catches all exceptions in the template apply phase. If you use ext-all-debug.js you do get a console.log statement, which is slightly better. But when using a non-debug version of Ext JS you get a silently broken grid. This is very bad as it completely hides errors from us developers, and tests won’t easily detect this.

“Fixing” the grid rendering

To be notified when a crash happens inside a custom renderer method, you can override the ‘strict’ property globally which skips the try/catch when templates are applying their data. Now you can catch grid rendering errors regardless of which version of Ext JS you use.

Ext.define("CZ.override.XTemplate", {
    override : "Ext.XTemplate",
    strict   : true
});

Overriding the console.log method

Another way to detect this issue is to override console.log in your test suite. We already do this internally for all our tests and it works great. Please note, Ext JS only uses console log in the debug version of the library – so make sure your tests use the debug version for this to work.

Harness.on('teststart', function (ev, test) {
    var console = test.global.console;

    if (console) {
        console.error = console.warn = function () {
            test.fail([].join.apply(arguments));
        };
    }
});

Hope one of the tricks above help you with your grids, happy hacking/testing!

Mats Bryntse
Mats Bryntse

Mats Bryntse is the founder and CEO of Bryntum, where he leads the team building advanced scheduling and project planning components for the web. He has spent the past 15 years focused on component performance, developer experience, and making complex user interfaces feel simple. Bryntum's components cover Gantt charts, data grids, calendars, schedulers, and Kanban boards, and Mats works across all of them, from API design to the details of rendering large data sets in the browser. Away from work he plays chess and badminton.

Ext JS

Try Bryntum components

Fast, framework-agnostic UI components for scheduling and project management.

Start a free trial

Related posts