ponichWebKnight opened a new pull request, #40907:
URL: https://github.com/apache/superset/pull/40907

   ### SUMMARY
   
     Adds header-click **server-side** sorting to the paginated/truncated table 
views so
     sorting reflects the **full dataset** rather than only the rows already 
loaded on the
     client. Previously, clicking a column header in these views either did 
nothing useful or
     only reordered the current page.
   
     **What changed**
   
     - **"View as table" results pane** (`DataTablesPane` → `GridTable`): 
clicking a column
       header now injects an `orderby` into the chart-data request and 
re-queries the server.
       - The server round-trip is **skipped** when the result already fits 
within the row
         limit (client-side sort is exact) — so small results stay instant.
       - It is also **skipped for queries with post-processing** (pivot / cum / 
rolling).
         `orderby` + `row_limit` apply to the raw SQL *before* post-processing, 
which would
         change the rows feeding those operations and produce incorrect values 
(e.g. a
         cumulative total computed over a truncated subset). Those views fall 
back to
         client-side sorting of what the chart actually produced.
       - The results pane stays mounted during a re-sort refetch, so the grid 
keeps its sort
         state/indicator instead of resetting.
   
     - **Multi-column sort**: the chart-data API now validates only that each 
`orderby`
       direction is a boolean and allows multiple sort columns; the table 
plugins'
       (the metric-based default is only applied when no `orderby` is provided).
       
     - **Drill to detail** (`DrillDetailPane`): column-header sort is wired 
through to
       `/datasource/samples` as a server-side `orderby`.
       - `SamplesPayloadSchema` accepts an `orderby` field.
       - `_get_drill_detail` preserves a caller-supplied `orderby`, defaulting 
to the first
         column only when none is given (previously it unconditionally forced 
the first
         column, ignoring the request). 
       - `orderby` is omitted from the `COUNT(*)` query (ordering a bare count 
by a data
         column is meaningless and errors on stricter databases). 
         
     **Design decisions / rationale**
     
     - Server-side sort is only enabled where the displayed columns map 
directly to the SQL
       result; post-processed charts are intentionally left to client-side sort 
to avoid
       returning incorrect data.
     - Sort-column validation is kept minimal at the API layer; unknown sort 
columns are
       rejected deeper in the query builder (`get_sqla_query` raises on 
unresolved columns),
       so injection-style column names cannot reach SQL.
       
     ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
     
   <img width="868" height="541" alt="Screenshot 2026-06-09 at 18 14 20" 
src="https://github.com/user-attachments/assets/dd912699-5818-4582-9a29-fd6c99b8e261";
 />
   <img width="910" height="430" alt="Screenshot 2026-06-09 at 18 09 34" 
src="https://github.com/user-attachments/assets/9ec51bcb-89cd-4913-9051-2ada26cd72aa";
 />
   <img width="909" height="465" alt="Screenshot 2026-06-09 at 18 09 41" 
src="https://github.com/user-attachments/assets/f278cf8a-80ac-43fc-8449-b0933932425d";
 />
   <img width="874" height="482" alt="Screenshot 2026-06-09 at 18 09 59" 
src="https://github.com/user-attachments/assets/a21fa5ee-4173-421a-a838-07b449d2dc3f";
 />
          
     ### TESTING INSTRUCTIONS
     
     Automated:
     - Backend unit tests:
       - `pytest tests/unit_tests/charts/data/test_api.py`
       - `pytest tests/unit_tests/views/datasource/utils_test.py`
       - `pytest tests/unit_tests/common/test_query_actions.py`
     - Backend integration test:
       - `pytest tests/integration_tests/datasource_tests.py -k 
samples_with_orderby`
       
     Manual:
     1. **Results pane (raw/non-post-processed chart):** open a chart whose 
result exceeds the
        row limit, open the **"View as table"** menu, click a column header → 
confirm the
        request re-fires with `queries[0].orderby` and the rows re-order by the 
full dataset
        (top-N changes), cycling asc → desc → off. 
     2. **Results pane (post-processed chart, e.g. Big Number with a cumulative 
trend):** click
        a column header → confirm sorting happens client-side with **no** 
server request and
        the displayed values stay correct (no truncated cumulative totals).
     3. **Drill to detail:** right-click a chart → *Drill to detail*, click a 
column header →
        confirm the `/datasource/samples` request includes `orderby`, rows sort 
server-side,
        and sorting persists while paging.
     4. **Multi-column sort:** Shift-click a second header in the results table 
→ confirm
        multiple `orderby` entries are sent and accepted.
        
     ### ADDITIONAL INFORMATION
     <!--- Check any relevant boxes with "x" -->
     <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
     - [ ] Has associated issue:
     - [ ] Required feature flags:
     - [x] Changes UI
     - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
       - [ ] Migration is atomic, supports rollback & is backwards-compatible
       - [ ] Confirm DB migration upgrade and downgrade tested
       - [ ] Runtime estimates and downtime expectations provided
     - [x] Introduces new feature or API
     - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to