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

chrtz picture chrtz  路  3Comments

abhinukala picture abhinukala  路  3Comments

OGhawsi picture OGhawsi  路  3Comments

daltonrooney picture daltonrooney  路  3Comments

daenuprobst picture daenuprobst  路  3Comments