Skip to content

Non-main views (summary stats etc) don't actually sort when user clicks a sortable header #741

@paddymul

Description

@paddymul

Summary

Surfaced in code review of #739 by chatgpt-codex-connector:
#739 (comment)

makeStaticInfiniteDs in packages/buckaroo-js-core/src/components/BuckarooWidgetInfinite.tsx is the fake IDatasource wrapping pre-loaded DFData arrays (summary stats and friends) so non-main views can share the AG-Grid rowModelType: "infinite" with the main view. The change there in #739 keeps the grid mounted across df_display swaps — that part is the intended win.

But its getRows just slices the input array and calls successCallback:

getRows: (params: IGetRowsParams) => {
    const slice = data.slice(params.startRow, params.endRow);
    params.successCallback(slice, data.length);
}

params.sortModel is ignored.

Impact

Pre-#739, summary stats and other non-main views were rendered through AG-Grid's client-side row model (data_type: "Raw"), which sorted rows in memory automatically when the user clicked a sortable header. After #739 they use the infinite row model with this fake datasource, so:

  • Sort UI on the column header still works (arrow flips, classes update)
  • Rows do not reorder
  • Net effect: clicking a sortable header on summary stats looks broken

Fix sketch

Sort the array inside getRows according to params.sortModel before slicing. Roughly:

getRows: (params: IGetRowsParams) => {
    const sm = params.sortModel;
    const sorted = sm.length === 0
        ? data
        : [...data].sort((a, b) => {
            for (const { colId, sort } of sm) {
                const av = a[colId], bv = b[colId];
                if (av === bv) continue;
                const cmp = av < bv ? -1 : 1;
                return sort === "desc" ? -cmp : cmp;
            }
            return 0;
        });
    params.successCallback(sorted.slice(params.startRow, params.endRow), data.length);
}

Mind: summary-stats rows often have mixed-type cell values (numbers, strings, nested objects, "—") — the comparator needs to handle that without throwing. Probably easiest to lean on lodash's _.orderBy for type-safe sorting.

Acceptance

  • Click any sortable column header on the summary-stats view of a real notebook df — rows reorder.
  • Sort indicator and order match the rendered rows.
  • No regression on the main infinite view (which goes through getDs, not this fake datasource).

Notes

Originally identified during the #739 review. Doesn't block #739 itself, but should land before the next release that ships #739.

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