Layout in JavaScript Pivot Table

The Syncfusion® JavaScript Pivot Table supports three visual layouts to present data according to different analytical needs:

  • Default Compact: Displays row fields hierarchically in a stepped, tree-like structure within a single column.
  • Classic (Tabular): Displays row fields side by side in separate columns with subtotals per group and grand totals.
  • Flat: Displays raw, unaggregated relational records directly in a flat tabular grid view.

Default Compact Layout

The compact layout is the default visual presentation of the Pivot Table. In this layout, fields placed on the row axis are rendered in a single column using an expandable and collapsible stepped hierarchy, which saves horizontal space while preserving the parent-child relationships between grouped rows.

The compact layout is active by default. You can also explicitly specify it by setting the layout property in gridSettings to Compact.

Classic Layout

The classic layout is compatible only with relational data sources and operates in both client-side and server-side engines.

The classic layout, also known as the tabular layout, in the Syncfusion® Pivot Table provides a structured, tabular presentation of data that enhances readability and usability. In this layout, fields in the row axis are displayed side by side in separate columns, making data interpretation and analysis easier. By default, grand totals appear at the end of all rows, while subtotals are placed in a separate row beneath each group. All other features of the pivot table, such as filtering, sorting, drag-and-drop, expand/collapse functionality, and more, remain the same as in the compact layout, which serves as the default hierarchical format of the pivot table.

To enable the classic layout, set the layout property in the gridSettings of the Pivot Table to Tabular.

var pivotObj = new ej.pivotview.PivotView({
    dataSourceSettings: {
        dataSource: pivotData,
        columns: [{ name: 'Year' }, { name: 'Quarter' }],
        rows: [
            { name: 'Product_Categories', caption: 'Product Categories' },
            { name: 'Products' },
            { name: 'Order_Source', caption: 'Order Source' },
        ],
        formatSettings: [{ name: 'Amount', format: 'C0' }],
        drilledMembers: [
            { name: 'Product_Categories', items: ['Accessories', 'Bikes'] },
            { name: 'Products', delimiter: '##', items: ['Accessories##Helmets'] },
        ],
        filterSettings: [
            {
                name: 'Products',
                type: 'Exclude',
                items: ['Cleaners', 'Fenders'],
            },
        ],
        expandAll: false,
        values: [
            { name: 'Sold', caption: 'Units Sold' },
            { name: 'Amount', caption: 'Sold Amount' },
        ],
        filters: [],
    },
    width: '100%',
    height: 450,
    showFieldList: true,
    gridSettings: {
        columnWidth: ej.base.Browser.isDevice ? 100 : 120,
        layout: 'Tabular',
    }
});
pivotObj.appendTo("#PivotTable");
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Pivot Grid</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Pivot Grid Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/35.2.12/tailwind3.css" rel="stylesheet" />

    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

    <script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
    <script src="es5-datasource.js" type="text/javascript"></script>
</head>

<body>

    <div id="container">
        <div>
            <div id="PivotTable"></div>
        </div>
    </div>

    <script>
        var ele = document.getElementById('container');
        if (ele) {
            ele.style.visibility = "visible";
        }   
    </script>
    <script src="index.js" type="text/javascript"></script>
</body>

</html>

Limitations

  • Subtotals at the “Top” position are not supported for row subtotals.

Flat Analytical Table View

By default, the Pivot Table aggregates relational data in the Compact or Tabular layout. The Flat layout instead displays the raw, unaggregated relational records in a tabular view without altering the pivot report configuration. It works directly on the dataSource of the dataSourceSettings and does not trigger any pivot engine population events.

To enable it, set the layout property in gridSettings to Flat and inject the FlatLayout module using ej.pivotview.PivotView.Inject(ej.pivotview.FlatLayout). Configure the flat view independently using flatSettings, which supports columns, allowSorting, sortSettings, allowFiltering, filterSettings, allowAdvancedFiltering, searchSettings, allowPaging, pageSettings, enableVirtualization, aggregates, totalsPosition and showColumnChooser. When the toolbar is enabled, add the Layout item to the toolbar array to let users switch between the Compact, Tabular and Flat layouts.

The Flat layout is supported only for relational data sources; OLAP is not supported. Switching layouts preserves the original pivot report state.

ej.pivotview.PivotView.Inject(ej.pivotview.FlatLayout);

var pivotObj = new ej.pivotview.PivotView({
    dataSourceSettings: { dataSource: pivotData },
    gridSettings: { layout: 'Flat' },
    flatSettings: {
    columns: [
    { field: 'Country', headerText: 'Country', width: 140 },
    { field: 'Products', headerText: 'Products', width: 160 },
    { field: 'Year', headerText: 'Year', width: 120 },
    { field: 'Sold', headerText: 'Units Sold', width: 120 },
    { field: 'Amount', headerText: 'Sold Amount', width: 140 }
],
    allowSorting: true,
    allowFiltering: true,
    allowPaging: true,
    pageSettings: { pageSize: 10 }
},
    width: '100%',
    height: 450
});
pivotObj.appendTo('#PivotTable');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Pivot Grid</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Pivot Grid Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/35.2.12/tailwind3.css" rel="stylesheet" />

    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

    <script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
    <script src="es5-datasource.js" type="text/javascript"></script>
</head>

<body>

    <div id="container">
        <div>
            <div id="PivotTable"></div>
        </div>
    </div>

    <script>
        var ele = document.getElementById('container');
        if (ele) {
            ele.style.visibility = "visible";
        }   
    </script>
    <script src="index.js" type="text/javascript"></script>
</body>

</html>