Enhanced jqxGrid

Cell templates

Rich cells without writing a cellsrenderer. Add a declarative cellTemplate to any column — a moustache string like {{first}} {{value | c2}}, or a built-in like { type: 'badge' }. It compiles to a standard renderer, so sort, filter, page and export keep working.

avatarbadgetagsprogresstrend money ±boolswatchreldatelink

jQuery Grid: Cell Templates

jqxGrid enhanced cell templates - declarative rich cells (badges, avatars, trends, progress, tags and more).

A live JavaScript/jQuery example of jqxGrid, the jQWidgets Grid component, with its complete source code below. It is one of 139 jqxGrid demos for jQuery.

jqxGrid API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxGrid shows the setup step by step.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxdata.js, jqxbuttons.js, jqxscrollbar.js, jqxmenu.js, jqxlistbox.js, jqxdropdownlist.js, jqxgrid.js, jqxgrid.filter.js, jqxgrid.sort.js, jqxgrid.selection.js, jqxgrid.pager.js, jqxgrid.celltemplates.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).

script.js

$(document).ready(function () {
    // ---- synthetic team / accounts data ----
    var FIRST = ['Alex', 'Sam', 'Jordan', 'Taylor', 'Morgan', 'Casey', 'Riley', 'Jamie', 'Avery', 'Quinn', 'Noah', 'Mia', 'Liam', 'Emma', 'Lucas', 'Olivia', 'Ethan', 'Ava', 'Leo', 'Zoe'];
    var LAST = ['Morgan', 'Chen', 'Patel', 'Kim', 'Garcia', 'Rossi', 'Nowak', 'Silva', 'Haddad', 'Weber', 'Ivanov', 'Okafor', 'Nguyen', 'Costa', 'Berg', 'Yamamoto'];
    var STATUS = ['Active', 'Trial', 'Paused', 'Churned'];
    var PLANS = ['Free', 'Pro', 'Enterprise'];
    var SKILLS = ['React', 'Vue', 'Angular', 'Node', 'Python', 'Go', 'SQL', 'Figma', 'AWS', 'Rust'];
    var COLORS = ['#2563eb', '#7c3aed', '#db2777', '#ea580c', '#0891b2', '#16a34a', '#f59e0b'];
    var DAY = 86400000, NOW = Date.now();
    function pick(a) { return a[Math.floor(Math.random() * a.length)]; }
    function rint(a, b) { return Math.floor(a + Math.random() * (b - a + 1)); }

    var data = [];
    for (var i = 0; i < 60; i++) {
        var first = pick(FIRST), last = pick(LAST), name = first + ' ' + last;
        var sk = [];
        for (var s = 0, n = rint(1, 3); s < n; s++) { var x = pick(SKILLS); if (sk.indexOf(x) === -1) { sk.push(x); } }
        data.push({
            name: name,
            email: (first + '.' + last).toLowerCase() + '@acme.io',
            status: pick(STATUS),
            plan: pick(PLANS),
            skills: sk.join(', '),
            usage: rint(5, 100),
            change: Math.round((Math.random() * 65 - 25) * 10) / 10,
            balance: rint(-600, 5200),
            verified: Math.random() > 0.4,
            color: pick(COLORS),
            lastSeen: NOW - rint(0, 60) * DAY - rint(0, DAY)
        });
    }

    var adapter = new $.jqx.dataAdapter({
        localdata: data, datatype: 'array', datafields: [
            { name: 'name', type: 'string' }, { name: 'email', type: 'string' },
            { name: 'status', type: 'string' }, { name: 'plan', type: 'string' },
            { name: 'skills', type: 'string' }, { name: 'usage', type: 'number' },
            { name: 'change', type: 'number' }, { name: 'balance', type: 'number' },
            { name: 'verified', type: 'bool' }, { name: 'color', type: 'string' },
            { name: 'lastSeen', type: 'number' }
        ]
    });

    $('#grid').jqxGrid({
        theme: 'tailwind', width: '100%', height: 560, source: adapter,
        sortable: true, filterable: true, pageable: true, pagesize: 10, columnsheight: 40, rowsheight: 48,
        columns: [
            // people & media
            { text: 'Member', datafield: 'name', width: 220, cellTemplate: { type: 'avatar', subField: 'email' } },
            // status & data-viz
            { text: 'Status', datafield: 'status', width: 118, cellTemplate: { type: 'badge', dot: true, colors: { Active: 'green', Trial: 'blue', Paused: 'amber', Churned: 'red' } } },
            { text: 'Plan', datafield: 'plan', width: 130, cellTemplate: { type: 'badge', colors: { Free: 'gray', Pro: 'violet', Enterprise: 'teal' } } },
            { text: 'Skills', datafield: 'skills', width: 165, cellTemplate: { type: 'tags', max: 2 } },
            { text: 'Usage', datafield: 'usage', width: 150, cellTemplate: { type: 'progress', thresholds: [{ at: 0, color: '#f59e0b' }, { at: 50, color: '#2563eb' }, { at: 85, color: '#16a34a' }] } },
            { text: 'MRR Δ', datafield: 'change', width: 96, cellsalign: 'right', cellTemplate: { type: 'trend' } },
            // formatting
            { text: 'Balance', datafield: 'balance', width: 116, cellsalign: 'right', cellTemplate: { type: 'money', signed: true } },
            { text: 'Verified', datafield: 'verified', width: 92, cellsalign: 'center', cellTemplate: { type: 'bool' } },
            { text: 'Brand', datafield: 'color', width: 120, cellTemplate: { type: 'swatch' } },
            { text: 'Last seen', datafield: 'lastSeen', width: 110, cellTemplate: { type: 'reldate' } },
            { text: 'Email', datafield: 'email', width: 200, cellTemplate: { type: 'link', kind: 'email' } }
        ]
    });
});

document.getElementById('badge').innerHTML = '<svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor"><path d="M12 2l1.7 4.6L18.3 8.3 13.7 10 12 14.6 10.3 10 5.7 8.3 10.3 6.6z"/></svg> Enhanced jqxGrid';

body.html

<div class="wrap">
    <span class="badge" id="badge">Enhanced jqxGrid</span>
    <h1>Cell templates</h1>
    <p class="lead">Rich cells without writing a <code>cellsrenderer</code>. Add a declarative <code>cellTemplate</code> to any column — a moustache string like <code>{{first}} {{value | c2}}</code>, or a built-in like <code>{ type: 'badge' }</code>. It compiles to a standard renderer, so sort, filter, page and export keep working.</p>

    <div class="legend">
        <span>avatar</span><span>badge</span><span>tags</span><span>progress</span><span>trend</span>
        <span>money ±</span><span>bool</span><span>swatch</span><span>reldate</span><span>link</span>
    </div>

    <div class="card"><div id="grid"></div></div>

</div>

Learn more

More jQuery Grid demos