bootstrap-table
bootstrap-table copied to clipboard
Get Row By Index
Description
Team,
Is there a way to get a row by index in addition to the unique id?
$table.bootstrapTable('getRowByUniqueId', 1) works great, but I'm attempting to modify the CRUD table example to add a Next and Previous button to the modal. Since the unique id may not be sequential I need a way to do the same thing with the index. I thought about using the scrollTo method and then just getting the row at index 0 but I'm not sure that will work or is the best. Any suggestions?
Thank you for this excellent project. If I can get my use case working it will save me weeks of development.
Example(s)
No response
You can use getData and then do whatever you want with it. Example:
<script>
const $table = $('#table')
const $button = $('#button')
$(function() {
$button.click(function () {
var data = $table.bootstrapTable('getData');
var currentIndex = data.findIndex(x => x.id == 1);
var nextRow = data[currentIndex + 1]
alert(JSON.stringify(nextRow))
})
})
</script>