simple-datatables

Documentation Demos

Colspan Support

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

Example 1: Colspan from HTML Table

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

ID First Name Last Name Department Email
1 John Doe Engineering john.doe@example.com
2 Jane Smith Marketing - jane.smith@example.com
3 Bob Johnson Sales bob.johnson@example.com
Alice Williams (Former Employee) HR alice.w@example.com

Example 2: Colspan from JSON/JavaScript Data

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

const data = {
    headings: ["ID", "Name", "Department", "Email", "Phone"],
    data: [
        {
            cells: [
                "1",
                {
                    data: "Full Name Here",
                    attributes: { colspan: "2" }  // Spans 2 columns
                },
                "email@example.com",
                "555-1234"
            ]
        }
    ]
};
Note: When using colspan, the total number of cells (including the colspan value) must match the number of headings.

Example 3: Advanced Colspan Usage

This example demonstrates more complex colspan scenarios, including cells spanning different numbers of columns.

Example 4: Colspan in Data Rows

This example shows colspan used in regular data cells (heading colspan support coming soon).