Auto fill number: Num1 ... NumX "Auto-Numbering"

I wonder if there is a way to auto fill numbers like the excel feature “Auto-Numbering”.

In excel one start to write

Num1
Num2

Then select both, then one can drag and drop the selection on the little square in the down right corner.
And excel will automatically count up:

Num3
Num4
etc…

Is there a similar feature in grist?

Edit: I know that i could utilize rows $id.
But in this case i think this is not a good option.

1 Like

This formula should do what you expect:

"Num{}".format(1 + table.lookupRecords(sort_by="manualSort").id.index($id))

If working on big tables, I guess the following one should be more efficient (cf. this post):

from sortedcontainers import SortedKeyList
"Num{}".format(1 + SortedKeyList(table.all, key=lambda x: x.manualSort).index(rec))

Yes this works, if i would like to have all rows numbered.

What i would like to do is the more manual way.
A user needs to insert some (~80) rows. These all rows must be numbered.
Box1
Box2

Box80

Then another box is added with ~45 Rows
Box1

Box45

so the user must decide if they need this counting.

image

Edit:

I think it would be more “grist like”, to split such stuff in multiple subtables and reference them.
But it would be still good to have such “Auto-Numbering” features when needed. Maybe i should open a github issue?

Given the “database-like” behavior of Grist, I think this would only be possible if you add a “Creation Date” column, with a trigger formula and the time function. That would give something like that:

"Num{}".format(1 + table.lookupRecords(
  Creation_Date=$Creation_Date,
  sort_by="manualSort"
).id.index($id))

And the Creation Date trigger formula would be:

from time import time
int(time())

It’s possible to elaborate with other kinds of conditions, like in this thread.

This table may be a starting point to illustrate all that.

Here is an answer to an earlier similar question, which shows something similar: Sequential Numbers using Drag - #4 by dmitry-grist. In particular, the example document referenced there has an in-group numbering example: Sequential Numbers - Grist.

For this one, you’d set the group manually (or fill in a range with the same group using the ⌘ D / Ctrl + D shortcut), and the incrementing numerical suffix is added automatically.

Still, the original request is different. It is indeed sometimes very convenient to fill in a range with auto-incrementing values. It may not be hard to implement, as long as the interface is simple. Dragging a box is not so simple, but another idea is to select a range, press that existing ⌘ D / Ctrl + D shortcut, and then ask the user with a popup if they want to fill in the range with the values in the top cell, or an arithmetic sequence based on the top two cells (when both options seem possible). If that sounds useful, opening a github issue is a good way to go.

Done:

also backlinked to this help page.

Also asked for here:

1 Like