BootstrapTable - move row position via insert+remove
// Bootstrap Table - move row position via `insertRow` and `remove`. Created to answer https://github.com/wenzhixin/bootstrap-table/issues/2541, ties in with official examples and doco at http://bootstrap-table.wenzhixin.net.cn/documentation/#methods
HTML
<link rel="stylesheet" href="https://rawgit.com/wenzhixin/bootstrap-table/master/src/bootstrap-table.css">
<script src="https://rawgit.com/wenzhixin/bootstrap-table/master/src/bootstrap-table.js"></script>
<table data-toggle="table" id="table"
data-url="/gh/get/response.json/wenzhixin/bootstrap-table/tree/master/docs/data/data1/"
data-unique-id="stargazers_count"
>
<thead>
<tr>
<th data-field="name">Name</th>
<th data-field="stargazers_count">Stars</th>
<th data-field="forks_count">Forks</th>
<th data-field="description">Description</th>
<th data-field="operation" data-formatter="operationFormatter" data-events="actionEvents">operation</th>
</tr>
</thead>
</table>
JavaScript
// Bootstrap Table - move row position via `insertRow` and `remove`. Created to answer https://github.com/wenzhixin/bootstrap-table/issues/2541, ties in with official examples and doco at http://bootstrap-table.wenzhixin.net.cn/documentation/#methods
function operationFormatter(){
return "<a type='button' class='move-up btn btn-sm btn-primary'><span class='glyphicon glyphicon-arrow-up'></span></a>"+"<a type='button' class='move-down btn btn-sm btn-primary'><span class='glyphicon glyphicon-arrow-down'></span></a>"
}
window.actionEvents = {
'click .move-down': function (e, value, row, index) {
if (index >= 0) {
console.log('.move-down',[e,value,row,index,$(this)])
// NOTE - works, remember it is 'values', not 'value', so wrap in array
// - if you want gurenteed unique, add an id field, doesnt even need a column but does have to be in the table data to be used. 'index' is a presentation value, not a field
// - you can also use 'removeByUniqueId' by adding a `data-unique-id` field
$("#table").bootstrapTable('remove', { field: 'stargazers_count', values: [row.stargazers_count] });
// NOTE - insert after remove, so assumingly only ever 1 with that unique value that gets removed
// - if not unique enough, make it unique, see notes above about 'id field'
$("#table").bootstrapTable("insertRow", {index: index + 1, row: row });
// NOTE - doesnt work, why would it???? See the examples and where they clearly show you what 'field' means, '$index' is NOT a field
// $("#table").bootstrapTable('remove', { field: '$index', values: [index] });
// NOTE - 'getRowByUniqueId' just gets data, use simple jquery to get added row
// console.log($('#table').bootstrapTable('getRowByUniqueId', row.stargazers_count))
$('.success').removeClass('success');
// NOTE - if you want to use...