jQuery Grid: Row Details

The Row Details 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, jqxmenu.js, jqxgrid.js, jqxgrid.selection.js, jqxtabs.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 () {
    // prepare the data
    var data = new Array();

    var firstNames = ["Nancy", "Andrew", "Janet", "Margaret", "Steven", "Michael", "Robert", "Laura", "Anne"];
    var lastNames = ["Davolio", "Fuller", "Leverling", "Peacock", "Buchanan", "Suyama", "King", "Callahan", "Dodsworth"];
    var titles = ["Sales Representative", "Vice President, Sales", "Sales Representative", "Sales Representative", "Sales Manager", "Sales Representative", "Sales Representative", "Inside Sales Coordinator", "Sales Representative"];
    var titleofcourtesy = ["Ms.", "Dr.", "Ms.", "Mrs.", "Mr.", "Mr.", "Mr.", "Ms.", "Ms."];
    var birthdate = ["03-Dec-80", "14-Feb-84", "25-Aug-95", "14-Sep-69", "27-Feb-87", "27-Jun-95", "24-May-92", "04-Jan-90", "22-Jan-98"];
    var hiredate = ["26-Apr-24", "09-Aug-24", "27-Mar-24", "28-Apr-25", "12-Oct-25", "12-Oct-25", "28-Dec-25", "28-Feb-26", "10-Nov-26"];
    var address = ["507 - 20th Ave. E. Apt. 2A", "908 W. Capital Way", "722 Moss Bay Blvd.", "4110 Old Redmond Rd.", "14 Garrett Hill", "Coventry House", "Miner Rd.", "Edgeham Hollow", "Winchester Way", "4726 - 11th Ave. N.E.", "7 Houndstooth Rd."];
    var city = ["Seattle", "Tacoma", "Kirkland", "Redmond", "London", "London", "London", "Seattle", "London"];
    var postalcode = ["98122", "98401", "98033", "98052", "SW1 8JR", "EC2 7JR", "RG1 9SP", "98105", "WG2 7LT"];
    var country = ["USA", "USA", "USA", "USA", "UK", "UK", "UK", "USA", "UK"];
    var homephone = ["(206) 555-9857", "(206) 555-9482", "(206) 555-3412", "(206) 555-8122", "(71) 555-4848", "(71) 555-7773", "(71) 555-5598", "(206) 555-1189", "(71) 555-4444"];
    var notes = ["Education includes a BA in psychology from Colorado State University in 2002.  She also completed 'The Art of the Cold Call.'  Nancy is a member of Toastmasters International.",
        "Andrew received his BTS commercial in 2006 and a Ph.D. in international marketing from the University of Dallas in 2013.  He is fluent in French and Italian and reads German.  He joined the company as a sales representative, was promoted to sales manager in January 2024 and to vice president of sales in March 2025.  Andrew is a member of the Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers Association.",
        "Janet has a BS degree in chemistry from Boston College (2016).  She has also completed a certificate program in food retailing management.  Janet was hired as a sales associate in 2023 and promoted to sales representative in February 2024.",
        "Margaret holds a BA in English literature from Concordia College (1990) and an MA from the American Institute of Culinary Arts (1998).  She was assigned to the London office temporarily from July through November 2024.",
        "Steven Buchanan graduated from St. Andrews University, Scotland, with a BSC degree in 2008.  Upon joining the company as a sales representative in 2024, he spent 6 months in an orientation program at the Seattle office and then returned to his permanent post in London.  He was promoted to sales manager in March 2025.  Mr. Buchanan has completed the courses 'Successful Telemarketing' and 'International Sales Management.'  He is fluent in French.",
        "Michael is a graduate of Sussex University (MA, economics, 2015) and the University of California at Los Angeles (MBA, marketing, 2018).  He has also taken the courses 'Multi-Cultural Selling' and 'Time Management for the Sales Professional.'  He is fluent in Japanese and can read and write French, Portuguese, and Spanish.",
        "Robert King served in the Peace Corps and traveled extensively before completing his degree in English at the University of Michigan in 2024, the year he joined the company.  After completing a course entitled 'Selling in Europe,' he was transferred to the London office in March 2025.",
        "Laura received a BA in psychology from the University of Washington.  She has also completed a course in business French.  She reads and writes French.",
        "Anne has a BA degree in English from St. Lawrence College.  She is fluent in French and German."];

    var k = 0;
    for (var i = 0; i < firstNames.length; i++) {
        var row = {};
        row["firstname"] = firstNames[k];
        row["lastname"] = lastNames[k];
        row["title"] = titles[k];
        row["titleofcourtesy"] = titleofcourtesy[k];
        row["birthdate"] = birthdate[k];
        row["hiredate"] = hiredate[k];
        row["address"] = address[k];
        row["city"] = city[k];
        row["postalcode"] = postalcode[k];
        row["country"] = country[k];
        row["homephone"] = homephone[k];
        row["notes"] = notes[k];
        data[i] = row;
        k++;
    }

    var source =
    {
        localdata: data,
        datatype: "array"
    };

    var initrowdetails = function (index, parentElement, gridElement, datarecord) {
        var tabsdiv = null;
        var information = null;
        var notes = null;
        tabsdiv = $($(parentElement).children()[0]);
        if (tabsdiv != null) {
            information = tabsdiv.find('.information');
            notes = tabsdiv.find('.notes');
            var title = tabsdiv.find('.title');
            title.text(datarecord.firstname);

            var container = $('<div style="margin: 5px;"></div>')
            container.appendTo($(information));
            var photocolumn = $('<div style="float: left; width: 15%;"></div>');
            var leftcolumn = $('<div style="float: left; width: 45%;"></div>');
            var rightcolumn = $('<div style="float: left; width: 40%;"></div>');
            container.append(photocolumn);
            container.append(leftcolumn);
            container.append(rightcolumn);

            var photo = $("<div class='jqx-rc-all' style='margin: 10px;'><b>Photo:</b></div>");
            var image = $("<div style='margin-top: 10px;'></div>");
            var imgurl = '../../images/' + datarecord.firstname.toLowerCase() + '.png';
            var img = $('<img height="60" src="' + imgurl + '"/>');
            image.append(img);
            image.appendTo(photo);
            photocolumn.append(photo);

            var firstname = "<div style='margin: 10px;'><b>First Name:</b> " + datarecord.firstname + "</div>";
            var lastname = "<div style='margin: 10px;'><b>Last Name:</b> " + datarecord.lastname + "</div>";
            var title = "<div style='margin: 10px;'><b>Title:</b> " + datarecord.title + "</div>";
            var address = "<div style='margin: 10px;'><b>Address:</b> " + datarecord.address + "</div>";
            $(leftcolumn).append(firstname);
            $(leftcolumn).append(lastname);
            $(leftcolumn).append(title);
            $(leftcolumn).append(address);

            var postalcode = "<div style='margin: 10px;'><b>Postal Code:</b> " + datarecord.postalcode + "</div>";
            var city = "<div style='margin: 10px;'><b>City:</b> " + datarecord.city + "</div>";
            var phone = "<div style='margin: 10px;'><b>Phone:</b> " + datarecord.homephone + "</div>";
            var hiredate = "<div style='margin: 10px;'><b>Hire Date:</b> " + datarecord.hiredate + "</div>";

            $(rightcolumn).append(postalcode);
            $(rightcolumn).append(city);
            $(rightcolumn).append(phone);
            $(rightcolumn).append(hiredate);

            var notescontainer = $('<div style="white-space: normal; margin: 5px;"><span>' + datarecord.notes + '</span></div>');
            $(notes).append(notescontainer);
            $(tabsdiv).jqxTabs({ width: 750, height: 170});
        }
    }
    var dataAdapter = new $.jqx.dataAdapter(source);

    $("#grid").jqxGrid(
    {
        width: getWidth('Grid'),
        height: 250,
        source: dataAdapter,
        rowdetails: true,
        rowdetailstemplate: { rowdetails: "<div style='margin: 10px;'><ul style='margin-left: 30px;'><li class='title'></li><li>Notes</li></ul><div class='information'></div><div class='notes'></div></div>", rowdetailsheight: 200 },
        ready: function () {
            $("#grid").jqxGrid('showrowdetails', 0);
            $("#grid").jqxGrid('showrowdetails', 1);
        },
        initrowdetails: initrowdetails,
        columns: [
              { text: 'First Name', datafield: 'firstname', width: 200 },
              { text: 'Last Name', datafield: 'lastname', width: 200 },
              { text: 'Title', datafield: 'title', width: 180 },
              { text: 'City', datafield: 'city', width: 100 },
              { text: 'Country', datafield: 'country'}
          ]
    });
});

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