[英]Sortable bootstrap table with rails gem
我正在使用bootstrap-table-rails gem为我的表创建可排序的功能。 除非我通过JS更改表字段中的数据,否则它工作正常。 我的代码如下所示:
<table data-toggle="table" class="table table-responsive">
<thead>
<tr>
<th data-field="date" data-sortable="true">TITLE</th>
<th data-field="deadline" data-sortable="true">DEADLINE</th>
<th data-field="accept-job" data-sortable="true"></th>
</tr>
</thead>
<tbody>
<tr>
<td>Sample data</td>
<td>Sample data</td>
<td class="accept_field"><button class="btn accept_btn">Accept Job</button></td>
</tr>
<tr>
<td>Sample data</td>
<td>Sample data</td>
<td>Sample data</td>
</tr>
</tbody>
基本上,该表包含两行,其中一行填充有虚拟数据,另一行填充了动态数据( deadline_field
)。 我通过JS这样更改数据:
function Timer(duration, display, deadline) {
var timer = duration, hours, minutes, seconds;
setInterval(function () {
hours = parseInt((timer /3600)%24, 10)
minutes = parseInt((timer / 60)%60, 10)
seconds = parseInt(timer % 60, 10);
hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.text(hours + ":" + minutes + ":" + seconds);
deadline.text(hours + ":" + minutes + ":" + seconds);
--timer;
}, 1000);
};
$(".accept-btn").click(function() {
var twentyFourHours = 24 * 60 * 60;
// Show timer element on page
var display = $('.countdown').show();
var deadline = $('.deadline_field');
Timer(twentyFourHours, display, deadline);
});
此功能执行以下操作:1.从24小时开始计时。 2.它在其他页面上和deadline_field
表中显示截止deadline_field
。 它工作得很好,但是当我尝试对表进行排序时, deadline_field
值已更改为Sample data
,即排序不再起作用。 非常感谢您对此问题的任何想法,谢谢。
经过数小时的研究,我决定切换到sorttable.js插件,该插件对我来说效果很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.