jQuery table sort

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

    You can use a jQuery plugin (breedjs) that provides sort, filter and pagination:

    HTML:

    Name Phone City Speciality
    {{person.name}} {{person.phone}} {{person.city}} {{person.speciality}}

    JS:

    $(function(){
      var data = {
        people: [
          {name: 'c', phone: 123, city: 'b', speciality: 'a'},
          {name: 'b', phone: 345, city: 'a', speciality: 'c'},
          {name: 'a', phone: 234, city: 'c', speciality: 'b'},
        ]
      };
      breed.run({
        scope: 'people',
        input: data
      });
      $("th[sort]").click(function(){
        breed.sort({
          scope: 'people',
          selector: $(this).attr('sort')
        });
      });
    });
    

    Working example on fiddle

提交回复
热议问题