jquery - 添加新行后刷新引导表
问题描述
我在启用了 detailView 的表上应用了引导表
$("table#orders").bootstrapTable({detailView: true});
它工作正常并显示加号(+)图标/按钮以查看详细信息。现在我正在向该表动态添加一个新行
$('table#orders').append('<tr><td>Some Date</td></tr>');
替换行后,它不显示新添加行的详细视图图标/按钮
尝试刷新后,它显示详细视图图标,但不显示新添加行的内容,而是显示旧行
$('table#orders').bootstrapTable('refresh');
关于这个问题的任何解决方法?
解决方案
Bootstrap-Table
作为附加行的 API -
$('#table').bootstrapTable('append',{ key: 'Data'});
工作演示 -
$('#table').bootstrapTable({
detailView: true,
detailFormatter: detailFormatter
});
$('#add').click(() => {
$('#table').bootstrapTable('append', {
0: 'Some Date'
});
});
function detailFormatter(index, row) {
return row[0];
}
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.16.0/dist/bootstrap-table.min.css">
<link href="https://unpkg.com/multiple-select@1.5.2/dist/multiple-select.min.css" rel="stylesheet">
</head>
<div class="container">
<h3>Bootstrap-table</h3>
<button id="add">
Add
</button>
<table id="table">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>First</td>
</tr>
<tr>
<td>Second</td>
</tr>
</tbody>
</table>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.16.0/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.16.0/dist/extensions/filter-control/bootstrap-table-filter-control.min.js"></script>
<script src="https://unpkg.com/multiple-select@1.5.2/dist/multiple-select.min.js"></script>
推荐阅读
- ruby - 在递归函数中将条件作为 Proc/Lambda/Block 传递会导致它在 lambda 内的条件评估为真后退出。为什么?
- java - mvn安装错误:包不存在
- reactjs - Axios 用 react + jest 发帖
- laravel - Laravel 中的列未更新
- jasperserver - Jaspersoft - HTTP 状态 404 - 实施基于令牌的身份验证时未找到
- swift - 如何在不连接它们的情况下在 MapView 上绘制两个 MKPolygons?
- javascript - 如何使用chart.js在饼图中显示切片内的切片值
- python-3.x - BlockingIOError: WinError 10035 无法立即完成非阻塞套接字操作
- python - 导入 sutime 模块时出现以下导入错误 - 这是什么意思?
- python - 如何让 tkinter 工作(在 vim 中)以及如何让 python-3.x 作为 linux 的默认 python 运行?