jQuery table sort

后端 未结 15 2911
温柔的废话
温柔的废话 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:40

    To the response of James I will only change the sorting function to make it more universal. This way it will sort text alphabetical and numbers like numbers.

    if( $.text([a]) == $.text([b]) )
        return 0;
    if(isNaN($.text([a])) && isNaN($.text([b]))){
        return $.text([a]) > $.text([b]) ? 
           inverse ? -1 : 1
           : inverse ? 1 : -1;
    }
    else{
        return parseInt($.text([a])) > parseInt($.text([b])) ? 
          inverse ? -1 : 1
          : inverse ? 1 : -1;
    }
    

提交回复
热议问题