Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [jQuery]Sortowanie tabeli względem jednego wiersza.
S_Olewniczak
post
Post #1





Grupa: Zarejestrowani
Postów: 189
Pomógł: 1
Dołączył: 28.01.2008

Ostrzeżenie: (0%)
-----


Napisałem prosty kod do sortowania tabeli względem jednego wiersza, którego indeks znamy. Wygląda on tak:
Kod
//now sort table
if(sort_td_index!=undefined) {
     $(table + ' tr:gt(1)').each(function() {
        act_tr_1 = this;
        act_td_1 = $('td:eq(' + sort_td_index + ')' ,this).html().toLowerCase();
        $(table + ' tr:gt(1)').each(function() {
            act_td_2 = $('td:eq(' + sort_td_index + ')' ,this).html().toLowerCase();
            if ((act_td_2 > act_td_1 && sort_opt=='asc') || (act_td_2 < act_td_1 && sort_opt=='desc')) {
                $(act_tr_1).insertBefore(this);
            }
        });
        
     });
}//end if

Jednak nie działa jak należy. Co robię źle?

Ten post edytował S_Olewniczak 6.07.2009, 09:40:15
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
vokiel
post
Post #2





Grupa: Zarejestrowani
Postów: 2 592
Pomógł: 445
Dołączył: 12.03.2007

Ostrzeżenie: (0%)
-----


1. czy table jest zmienną? Na co wskazuje?
2. console.log() => debugowanie:) (podgląd w firebugu)
3. zobacz jeśli this zastąpisz $(this)
4. skąd się bierze sort_td_index?

  1. <?php
  2. if(sort_td_index!=undefined) {
  3. // jesli table ma się donosić do tabeli to wrzuć w apostrofy $('table tr:gt(1)')
  4.     $(table + ' tr:gt(1)').each(function() {
  5.        act_tr_1 = $(this);
  6.        act_td_1 = $('td:eq(' + sort_td_index + ')' ,$(this)).html().toLowerCase();
  7. console.log(act_td_1); //debugowanie ;)
  8.        $(table + ' tr:gt(1)').each(function() {
  9.            act_td_2 = $('td:eq(' + sort_td_index + ')' ,$(this)).html().toLowerCase();
  10.            if ((act_td_2 > act_td_1 && sort_opt=='asc') || (act_td_2 < act_td_1 && sort_opt=='desc')) {
  11.                act_tr_1.insertBefore($(this));
  12.            }
  13.        });
  14.     });
  15. }
  16. ?>


btw. a czy sortowanie nie powinno być względem kolumny?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.10.2025 - 19:14