按“团队名称”在jquery中的特定列对表行进行排序

安吉·卡蒂里亚(Ankit Kathiriya)

这是我的桌子主体。

<tbody id="TeamsTbody">
    <tr title="Edit" class="edit">
        <td class="TeamName">Petes Team2</td>
        <td class="edit-delete">
            <a title="Edit" href="#"><i class="icon-edit MR5"></i></a>
            <a title="delete" href="#"><i class="icon-trash MR5"></i></a>
        </td>
    </tr>
    <tr title="Edit" class="edit">
        <td class="TeamName">Bens Test Team</td>
        <td class="edit-delete">
            <a title="Edit" href="#"><i class="icon-edit MR5"></i></a>
            <a title="delete" href="#"><i class="icon-trash MR5"></i></a>
        </td>
    </tr>
    <tr title="Edit" class="edit">
        <td class="TeamName">A New Team</td>
        <td class="edit-delete">
            <a title="Edit" href="#"><i class="icon-edit MR5"></i></a>
            <a title="delete" href="#">
                <i class="icon-trash MR5"></i>
            </a>
        </td>
    </tr>
</tbody>

我希望此表按特定column ..的排序顺序,请帮助我进行此操作。谢谢。

帕特·特里维第(Parth Trivedi)

可能会对您有帮助。您不需要任何第三方库。

$("table tr").sort(sort_li) // sort elements
                  .appendTo('.tblTeam'); // append again to the list
// sort function callback
function sort_li(a, b){      
    return ($(b).find('.TeamName').text()) < ($(a).find('.TeamName').text()) ? 1 : -1;    
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="tblTeam">
  <tr>
    <td class="TeamName">
      XYZ
      </td>
    </tr>
   <tr>
    <td class="TeamName">
      ABC
      </td>
     
    </tr>
  <tr>
     <td class="TeamName">
      PQR
      </td>
    </tr>
  </table>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章