Skip to content

Conversation

@nishantmonu51
Copy link
Collaborator

@nishantmonu51 nishantmonu51 commented Dec 11, 2025

Notion PRD here. The Notion PRD should serve as the source of truth for this feature.

https://www.notion.so/rilldata/Pivot-row-limit-for-nested-dimensions-2c7ba33c8f5780ff8ddfdd9fd94cfeda?source=copy_link

Add row limit control to pivot tables

This PR adds a configurable row limit feature to pivot tables, allowing users to control how many child rows are displayed under each dimension.

Changes

UI Components:

  • Added "Row limit" dropdown selector in pivot toolbar with options: 5, 10, 25, 50, 100, All
  • Only visible in pivot table mode (not flat table mode)
  • Includes tooltip explaining the limit applies to child rows under each dimension

State Management:

  • Added rowLimit?: number field to PivotState (undefined = unlimited)
  • Created setPivotRowLimit reducer that resets pagination, expanded state, and active cell when limit changes
  • Integrated row limit into URL state for sharing/bookmarks via row_limit parameter

Data Queries:

  • Applied limit to all data-fetching queries:
    • Column dimension axes
    • Row dimension axes
    • Table cell data
    • Expanded row data
    • Measure totals for sorting

pivot-limit
Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@medriscoll
Copy link
Contributor

@mindspank
Copy link
Contributor

When navigating from Pivot -> Explore -> Pivot we lose the limit setting

@mindspank
Copy link
Contributor

several issues with expanded rows and limits:

  • When changing limit with a expanded row, it does not work
  • When changing limit it re-renders the table and thus also closes any expanded rows, they need to stay open

@mindspank
Copy link
Contributor

It seems export is broken, it does no longer sort on the measure

@mindspank
Copy link
Contributor

totals are not respecting limits

@djbarnwal djbarnwal self-assigned this Dec 16, 2025
@djbarnwal djbarnwal changed the title [DRAFT] implementation for pivot row limit feat: add pivot row limit Dec 16, 2025
Copy link
Contributor

@ericpgreen2 ericpgreen2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared Constants for Row Limit Options

The allowed row limit values are defined in two places:

  • PivotToolbar.svelte (UI options): [5, 10, 25, 50, 100, "all"]
  • convertURLToExplorePreset.ts (URL validation): [5, 10, 25, 50, 100]

If these drift out of sync, users could set a limit via the UI that gets rejected when loaded from a URL. Consider extracting these to a shared constant, perhaps in types.ts or a new pivot-constants.ts file.

Extract Limit Calculation Logic

The new limit calculation in pivot-data-store.ts:298-315 is correct, but it's added to an already deeply nested section of createPivotDataStore. This makes the code harder to follow. Consider extracting this into a helper function, along these lines:

function calculateEffectiveRowLimit(
  rowLimit: number | undefined,
  rowOffset: number,
  pageSize: number,
): string {
  if (rowLimit === undefined) {
    return pageSize.toString();
  }
  const remainingRows = rowLimit - rowOffset;
  if (remainingRows <= 0) {
    return "0";
  }
  return Math.min(remainingRows, pageSize).toString();
}

This will make the intent clearer and keep the main function from growing further. More broadly, createPivotDataStore has become difficult to maintain due to its size and nesting depth. We should revisit this in the future to improve readability.

Expanded Row Limit Behavior

In pivot-expansion.ts:284-287:

const expandLimitToApply =
  config.pivot.rowLimit !== undefined
    ? config.pivot.rowLimit.toString()
    : "100";

When "All" is selected, expanded sections still cap at 100 rows. This might surprise users who expect "All" to mean unlimited everywhere. If this is intentional, it would be worth documenting. If not, consider whether expanded rows should also be unlimited when rowLimit is undefined.

Test Coverage Required

Before merging, please add test coverage for:

  • URL round-trip: setting a limit produces the correct row_limit param, and loading that URL restores the correct state
  • Edge cases in convertURLToExplorePreset.ts: invalid values, out-of-range numbers, non-numeric strings

Developed in collaboration with Claude Code

@ericpgreen2
Copy link
Contributor

@AdityaHegde, I've tagged you as a reviewer as well– can you please review the state management code?

Copy link
Collaborator

@AdityaHegde AdityaHegde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the intention to limit the top level dimension as well? Currently even that is limited (based on the query sent)

const expandLimitToApply =
config.pivot.rowLimit !== undefined
? config.pivot.rowLimit.toString()
: "100";
Copy link
Collaborator

@AdityaHegde AdityaHegde Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this limit should stay along with PIVOT_ROW_LIMIT_OPTIONS.

Also the hardcoded limit of 100 is already in PIVOT_ROW_LIMIT_OPTIONS. Since all and 100 are the same we should get rid of 100 option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a See more button based on product's recommendation. The max limit is still capped to 100.

@mindspank mindspank self-requested a review December 18, 2025 13:40
Copy link
Contributor

@ericpgreen2 ericpgreen2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, though see below for a few observations on complexity

@ericpgreen2
Copy link
Contributor

A few observations on complexity for future reference (not blocking):

Magic Number 100

The max row limit 100 appears in multiple places without a named constant:

  • pivot-expansion.ts:284: const effectiveLimit = localLimit ?? config.pivot.rowLimit ?? 100;
  • pivot-expansion.ts:527: expandedRowData.effectiveLimit < 100

Consider extracting to MAX_ROW_LIMIT in pivot-constants.ts for consistency with PIVOT_ROW_LIMIT_OPTIONS.

Row ID String Manipulation

In PivotTable.svelte:205-206:

const expandIndex = rowId.split(".").slice(0, -1).join(".");

This relies on the internal row ID format (dot-separated indices). Consider colocating utility functions for row ID manipulation in pivot-utils.ts or pivot-constants.ts - something like getParentExpandIndex(rowId) - to consolidate this logic in one place and make the format dependency explicit.

queryExpandedRowMeasureValues Complexity

This function now has 6 return paths, each including hasMore and effectiveLimit. If someone adds a new return path and forgets these fields, it could cause subtle bugs. Worth keeping an eye on as this file evolves.


Developed in collaboration with Claude Code

Copy link
Collaborator

@AdityaHegde AdityaHegde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels weird to look at top level dimensions with limit applying to them as well. Do we need "Load more" button there as well? Also lets update the PRD to make sure everyone is on the same page (it still states the limit is only for nested dimensions). cc @nishantmonu51 @mindspank

Also Increase limit to <new limit> on <dimension> feels a bit too verbose. How about just load more or load more for <dimension>?

@djbarnwal djbarnwal merged commit c02e241 into main Dec 19, 2025
16 checks passed
@djbarnwal djbarnwal deleted the pivot-limit branch December 19, 2025 07:24
djbarnwal added a commit that referenced this pull request Dec 19, 2025
* Initial implementation for pivot row limit

* Fix pivit config key to include row limit

* review fixes

* remove limit on col dimensions

* fix pagination

* remove limit on derived table cell data

* update key copy

* remove redundant limit from measure totals query

* adjust row limit label padding

* collapse all when limit is changed

* review

* add increase limit option under nested dimensions

* use common props for pivot cells

* show more copy update

* review updates

* gray out show more row

---------

Co-authored-by: Dhiraj Kumar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants