How to add sequence numbers to the table 1,2,3,4.. and the order never changes when users sort other columns?
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 }}
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.