simple-datatables

Documentation Demos

Rowspan Support

Simple-datatables supports rowspan attributes in table cells, allowing cells to span multiple rows. This works for both tables loaded from HTML and data loaded from JSON/JavaScript.

Example 1: Rowspan from HTML Table

When initializing from an existing HTML table, rowspan attributes are automatically preserved.

Department Team Employee Position Email
Engineering Frontend Alice Johnson Lead Developer alice@example.com
Bob Smith Developer bob@example.com
Backend Carol Williams Senior Developer carol@example.com
Marketing Social Media David Brown Social Media Manager david@example.com
Content Eve Davis Content Writer eve@example.com

Example 2: Rowspan from JSON/JavaScript Data

When loading data programmatically, you can specify rowspan by including an attributes object in your cell data.

const data = {
    headings: ["Department", "Employee", "Position", "Email", "Phone"],
    data: [
        {
            cells: [
                {
                    data: "Engineering",
                    attributes: { rowspan: "2" }  // Spans 2 rows
                },
                "John Doe",
                "Senior Developer",
                "john@example.com",
                "555-1234"
            ]
        },
        [
            "Jane Smith",
            "Developer",
            "jane@example.com",
            "555-5678"
        ]
    ]
};
Note: When using rowspan, subsequent rows should have fewer cells in the input data. The rowspan cell automatically fills those positions.

Example 3: Advanced Rowspan Usage

This example demonstrates more complex rowspan scenarios, including nested groupings.

Example 4: Combined Colspan and Rowspan

Cells can have both colspan and rowspan attributes simultaneously.