jQuery table sort

后端 未结 15 2659
温柔的废话
温柔的废话 2020-11-22 09:00

I have a very simple HTML table with 4 columns:

Facility Name, Phone #, City, Specialty

I want the user to be able to sort by Faci

15条回答
  •  既然无缘
    2020-11-22 09:51

    I love this accepted answer, however, rarely do you get requirements to sort html and not have to add icons indicating the sorting direction. I took the accept answer's usage example and fixed that quickly by simply adding bootstrap to my project, and adding the following code:

    inside each so that you have a place to set the icon.

    setIcon(this, inverse);

    from the accepted answer's Usage, below the line:

    th.click(function () {

    and by adding the setIcon method:

    function setIcon(element, inverse) {
    
            var iconSpan = $(element).find('div');
    
            if (inverse == false) {
                $(iconSpan).removeClass();
                $(iconSpan).addClass('icon-white icon-arrow-up');
            } else {
                $(iconSpan).removeClass();
                $(iconSpan).addClass('icon-white icon-arrow-down');
            }
            $(element).siblings().find('div').removeClass();
        }
    

    Here is a demo. --You need to either run the demo in Firefox or IE, or disable Chrome's MIME-type checking for the demo to work. It depends on the sortElements Plugin, linked by the accepted answer, as an external resource. Just a heads up!

提交回复
热议问题