1- The solution is short, yet may look a bit tricky, so here I provide it with extensive comments :
1+ Çözüm kısa, ancak biraz kafa karıştırıcı görünebilir, bu yüzden burada kapsamlı yorumlar sunuyorum :
22
33
44``` js
@@ -9,11 +9,11 @@ let sortedRows = Array.from(table.rows)
99table .tBodies [0 ].append (... sortedRows);
1010```
1111
12- 1 . Get all ` <tr> ` , like ` table.querySelectorAll('tr') ` , then make an array from them, cause we need array methods .
13- 2 . The first TR (` table.rows[0] ` ) is actually a table header, so we take the rest by ` .slice(1) ` .
14- 3 . Then sort them comparing by the content of the first ` <td> ` (the name field) .
15- 4 . Now insert nodes in the right order by ` .append(...sortedRows) ` .
12+ 1 . ` table.querySelectorAll('tr') ` gibi tüm ` <tr> ` leri al, sonra onlardan bir array yap, çünkü array yöntemlerine ihtiyacımız var .
13+ 2 . İlk TR (` table.rows[0] ` ) aslında bir tablo başlığıdırö bu yüzden geri kalanını ` .slice(1) ` ile alıyoruz .
14+ 3 . Daha sonra onları ilk ` <td> ` (isim alanı)'nın içeriği ile karşılaştıryoruz .
15+ 4 . Şimdi düğümleri ` .append(...sortedRows) ` olarak doğru sırada ekleyin .
1616
17- Tables always have an implicit <tbody > element, so we need to take it and insert into it: a simple ` table.append(...) ` would fail .
18-
19- Please note: we don't have to remove them, just "re-insert", they leave the old place automatically .
17+ Tobloların doğrudan belirtilmeyen bir <tbody > öğesi vardır, bu yüzden onu alır ve içine ekleriz: basit bir ` table.append(...) ` başarısız olacaktır .
18+
19+ Lütfen not edin: Onları kaldırmak zorunda değiliz, sadece "re-insert" (yeniden ekle), onlar eski yerlerini kendiliğinden bırakacaktır .
0 commit comments