(core) Update documentation for lookup/find/prevnext for the Help Center

Summary: Documentation in https://github.com/gristlabs/grist-help/ is built using `./build-functions.sh`, and the current version (as updated and landed in https://github.com/gristlabs/grist-help/pull/368) already reflects the changes in this diff.

Test Plan: No changes to functionality, only documentation comments.

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D4306
This commit is contained in:
Dmitry S
2024-07-31 09:52:02 -07:00
parent 69aabd1ae0
commit 95320f3f5b
3 changed files with 47 additions and 32 deletions

View File

@@ -5,24 +5,33 @@ def PREVIOUS(rec, *, group_by=(), order_by):
column IDs, and `order_by` allows column IDs to be prefixed with "-" to reverse sort order.
For example,
- `PREVIOUS(rec, order_by="Date")` will return the previous record when the list of records is
sorted by the Date column.
- `PREVIOUS(rec, order_by="-Date")` will return the previous record when the list is sorted by
the Date column in descending order.
- `PREVIOUS(rec, group_by="Account", order_by="Date")` will return the previous record with the
same Account as `rec`, when records are filtered by the Account of `rec` and sorted by Date.
```python
PREVIOUS(rec, order_by="Date") # The previous record when sorted by increasing Date.
PREVIOUS(rec, order_by="-Date") # The previous record when sorted by decreasing Date.
```
You may use `group_by` to search for the previous record within a filtered group. For example,
this finds the previous record with the same Account as `rec`, when records are filtered by the
Account of `rec` and sorted by increasing Date:
```python
PREVIOUS(rec, group_by="Account", order_by="Date")
```
When multiple records have the same `order_by` values (e.g. the same Date in the examples above),
the order is determined by the relative position of rows in views. This is done internally by
falling back to the special column `manualSort` and the row ID column `id`.
Use `order_by=None` to find the previous record in an unsorted table (when rows may be
rearranged by dragging them manually). For example,
- `PREVIOUS(rec, order_by=None)` will return the previous record in the unsorted list of records.
rearranged by dragging them manually). For example:
```python
PREVIOUS(rec, order_by=None) # The previous record in the unsorted list of records.
```
You may specify multiple column IDs as a tuple, for both `group_by` and `order_by`. This can be
used to match views sorted by multiple columns. For example:
- `PREVIOUS(rec, group_by=("Account", "Year"), order_by=("Date", "-Amount"))`
```python
PREVIOUS(rec, group_by=("Account", "Year"), order_by=("Date", "-Amount"))
```
"""
return _sorted_lookup(rec, group_by=group_by, order_by=order_by)._find.previous(rec)
@@ -39,10 +48,10 @@ def RANK(rec, *, group_by=(), order_by, order="asc"):
`order_by`, and grouping specified by `group_by`. See [`PREVIOUS`](#previous) for details of
these parameters.
The `order` parameter may be "asc" (which is the default) or "desc".
The `order` parameter may be `"asc"` (which is the default) or `"desc"`.
When `order` is "asc" or omitted, the first record in the group in the sorted order would have
the rank of 1. When `order` is "desc", the last record in the sorted order would have the rank
When `order` is `"asc"` or omitted, the first record in the group in the sorted order would have
the rank of 1. When `order` is `"desc"`, the last record in the sorted order would have the rank
of 1.
If there are multiple groups, there will be multiple records with the same rank. In particular,
@@ -50,7 +59,7 @@ def RANK(rec, *, group_by=(), order_by, order="asc"):
For example, `RANK(rec, group_by="Year", order_by="Score", order="desc")` will return the rank of
the current record (`rec`) among all the records in its table for the same year, ordered by
score.
decreasing score.
"""
return _sorted_lookup(rec, group_by=group_by, order_by=order_by)._find.rank(rec, order=order)