jQuery Grid: Image Column

The Image Column demo of the jQuery Grid.

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, jqxlistbox.js, jqxdropdownlist.js, jqxmenu.js, jqxgrid.js, jqxgrid.pager.js, jqxgrid.selection.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 () {
    var movies = new Array();

    // Avatar
    movies[0] = { Image: 'avatar.png', Title: 'Avatar', Year: 2009 };
    movies[1] = { Image: 'priest.png', Title: 'Priest', Year: 2006 };
    movies[2] = { Image: 'endgame.png', Title: 'End Game', Year: 2006 };
    movies[3] = { Image: 'unknown.png', Title: 'Unknown', Year: 2011 };
    movies[4] = { Image: 'unstoppable.png', Title: 'Unstoppable', Year: 2010 };
    movies[5] = { Image: 'twilight.png', Title: 'Twilight', Year: 2008 };
    movies[6] = { Image: 'kungfupanda.png', Title: 'Kung Fu Panda', Year: 2008 };
    movies[7] = { Image: 'knockout.png', Title: 'Knockout', Year: 2011 };
    movies[8] = { Image: 'theplane.png', Title: 'The Plane', Year: 2010 };
    movies[9] = { Image: 'bigdaddy.png', Title: 'Big Daddy', Year: 1999 };

    var imagerenderer = function (row, datafield, value) {
        return '<img style="margin-left: 5px;" height="60" width="50" src="../../images/' + value + '"/>';
    }

    var source = { localdata: movies, datatype: "array" };
    var dataAdapter = new $.jqx.dataAdapter(source);
    // Create jqxGrid.
    $("#grid").jqxGrid(
    {
        width: 400,
        source: dataAdapter,
        rowsheight: 60,
        columns: [
          { text: 'Image', datafield: 'Image', width: 60, cellsrenderer: imagerenderer },
          { text: 'Title', datafield: 'Title', width: 200 },
          { text: 'Year', datafield: 'Year' }
       ]
    });
});

body.html

<div id="jqxWidget" style="font-size: 13px; font-family: Verdana; float: left;">
    <div id="grid">
    </div>
</div>

Learn more

More jQuery Grid demos