javascript - 追加后如何对动态表数据进行排序

标签 javascript php jquery html tablesorter

您好,我正在尝试对过滤后的学生进行排序。过滤完我要附加的学生和按钮和文本的类,如下图所示。 enter image description here 我的动态代码将像这样返回 HTML:

<tbody>

<tr>
<td><span><img></span><p>Rasmus1 Lerdorf</p><p><b>Hallticket</b> : S28J1</p></td>
<td style="line-height:45px">4</td>
<td style="line-height:45px">9</td>
<td style="line-height:45px">8</td>
<td style="line-height:45px">4.5</td>
<td><span id="stu28" class="btn btn-danger reject-student selection-class">Not Selected</span></td>
<td style="line-height:45px"><input class="overrideStudent" type="text" name="picomment[28]"></td>
</tr>

<tr>
<td><span><img></span><p>Bill Gates</p><p><b>Hallticket</b> : S29J1</p></td>
<td style="line-height:45px">9</td>
<td style="line-height:45px">10</td>
<td style="line-height:45px">8</td>
<td style="line-height:45px">6.1</td>
<td><span id="stu28" class="btn  selection-class btn-success select-student">Selected</span></td>
<td style="line-height:45px"><input class="overrideStudent" type="text" name="picomment[29]"></td>
</tr>

</tbody>

我想先向选定的学生展示我该怎么做......?

这是我的 javascript 代码|:

success: function (response) {
    $(".selection-class").addClass('btn-danger reject-student');
    $(".selection-class").removeClass('btn-success select-student');
    $(".selection-class").text('Not Selected');
    $.each(response['students'], function(k, student) {
        $("#stu"+student.student_id).removeClass('btn-danger reject-student');
        $("#stu"+student.student_id).addClass('btn-success select-student');
        $("#stu"+student.student_id).text('Student Selected');
    });
    $("#success_message").show();
    $("#success_message").html(response['message']);

最佳答案

我将其设为按钮点击功能,但您可以将其更改为您的成功功能

$('#filter').click(function() {
  $('tr').hide();
  $('table > tbody > tr > td').find('.filterstudent').each(function() {
    var result1 = $(this).text();
    if (result1 == 'Selected') {
      $(this).closest("tr").show();
    }
  });
  var row = $('tr:hidden').show();
  row.insertAfter( row.next() );
});

https://jsfiddle.net/ppuaLedw/

关于javascript - 追加后如何对动态表数据进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41977545/

相关文章:

php - ajax + php 登录并具有访问级别

javascript - 如何从提交的按钮帖子上的 Javascript 返回并访问对象?

javascript - Foreach 无法在 php 和 Jquery 中工作

javascript - AJAX 使用 Servlet 参数为 null

javascript - 使用 jQuery 遍历 div

javascript - 未定义窗口 - react-draft-wysiwyg 与下一个 js (ssr) 一起使用

php - Laravel hasMany 方法不起作用

php - 如何在不中断用户访问的情况下每月刷新大型数据库表

php - Google Places API 网络服务 (PHP) : how to get 'administrative_area_2 place_id' for a given 'place_id'

php - 通知: Undefined index ajax