Skip to content

Using row number as an index, or creating expression column with row number #2207

Answered by texodus
sv2 asked this question in Q&A
Discussion options

You must be logged in to vote

Internally perspective creates this column already. We should expose this column as a normal perspective column, but don't currently, so there's no way today to do this entirely in-engine today.

You can currently access the internal index column in un-grouped View's only, by providing the id flag when calling a to_*() method, where you'll find the row's internal id in the __ID__ field:

const json = view.to_json({id: true})
const first_row_id = json[0].__ID__;

You can't yet update on it though, e.g. table.update({__ID__: [12], ...}) won't work today, so you'll still need to mutate the data for now.

We're also adding id() as an exprtk function, but this is more of a hack for your use case …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sv2
Comment options

Answer selected by sv2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants