Buefy: Add sequence numbers to table

Created on 25 May 2018  路  3Comments  路  Source: buefy/buefy

How to add sequence numbers to the table 1,2,3,4.. and the order never changes when users sort other columns?

Most helpful comment

ravenvn,

Try the following using only the front-end

<b-table :data="data">
<template slot-scope="props">
<b-table-column label="Nr.">
{{props.index + 1}}
</b-table-column>
// Other table columns
</template>
</b-table>

when you add sorting to the table the index sequences stay the same.

All 3 comments

It's the back-end job. We just need add a key serial to the result and display it as a new b-table-column.

$startSerial = ($request->page - 1) * $request->perPage + 1;
$results->map(function (&$item) use (&$startSerial) {
    $item['serial'] = $startSerial++;
});

AND

<b-table-column field="serial" label="#" width="40" numeric>
    {{ props.row.serial }}
</b-table-column>

ravenvn,

Try the following using only the front-end

<b-table :data="data">
<template slot-scope="props">
<b-table-column label="Nr.">
{{props.index + 1}}
</b-table-column>
// Other table columns
</template>
</b-table>

when you add sorting to the table the index sequences stay the same.

my solution 2021: {{ data.indexOf(props.row) + 1 }}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

itielshwartz picture itielshwartz  路  3Comments

sempixel picture sempixel  路  3Comments

kylebradshaw picture kylebradshaw  路  3Comments

dangminhtruong picture dangminhtruong  路  3Comments

chrtz picture chrtz  路  3Comments