Skip to content

How to set order of vals entries? #54

@fhg-isi

Description

@fhg-isi

I pass vals in a distinct order but PivotTable shows them in alphabetical order. How to keep the original order?

import dash
from dash import html
from dash_pivottable import PivotTable

# Sample data
data = [
    {"Category": "A", "Year": "2020", "Value1": 100, "Value2": 200},
    {"Category": "B", "Year": "2020", "Value1": 150, "Value2": 250},
    {"Category": "A", "Year": "2021", "Value1": 200, "Value2": 300},
    {"Category": "B", "Year": "2021", "Value1": 250, "Value2": 350},
]

# Create the Dash app
app = dash.Dash(__name__)

app.layout = html.Div(
    children=[
        PivotTable(
            id="pivot-table",
            data=data,
            rows=["Category"],
            cols=["Year"],
            vals=["Value2", "Value1"],  # Intentionally ordered as Value2, Value1
            aggregatorName="Sum",
            rendererName="Table",
        )
    ]
)

if __name__ == "__main__":
    app.run_server(debug=True)

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions