SORU
1 Temmuz 2010, PERŞEMBE


jQuery tablo sıralama

4 sütun ile çok basit bir HTML tablo var:

Facility Name, Phone #, City, Specialty

Bu Tesis kullanıcı adı ve Şehri tek sıralamak mümkün olmak istiyorum.

Nasıl bu kullanarak jQuery kodunu alabilir miyim?

CEVAP
1 Temmuz 2010, PERŞEMBE


Eğer çan ve ıslık sonra tüm önlemek istiyorsanız this simple sortElements plugin öneririm. Kullanımı:

var table = $('table');

$('#facility_header, #city_header')
    .wrapInner('<span title="sort this column"/>')
    .each(function(){

        var th = $(this),
            thIndex = th.index(),
            inverse = false;

        th.click(function(){

            table.find('td').filter(function(){

                return $(this).index() === thIndex;

            }).sortElements(function(a, b){

                if( $.text([a]) == $.text([b]) )
                    return 0;

                return $.text([a]) > $.text([b]) ?
                    inverse ? -1 : 1
                    : inverse ? 1 : -1;

            }, function(){

                // parentNode is the element we want to move
                return this.parentNode; 

            });

            inverse = !inverse;

        });

    });

And a demo.("Ekle" ve "tesis sütun başlıkları sıralamak için"). şehir

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ArkticPlanet

    ArkticPlanet

    9 ŞUBAT 2010
  • Photoshop Tutorials

    Photoshop Tu

    22 HAZİRAN 2011
  • WOSU Public Media

    WOSU Public

    23 AĞUSTOS 2007