File tree Expand file tree Collapse file tree
2-ui/2-events/03-event-delegation/3-sortable-table Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525 < table id ="grid ">
2626 < thead >
2727 < tr >
28- < th data-type ="number "> Age </ th >
29- < th data-type ="string "> Name </ th >
28+ < th data-type ="number "> Возраст </ th >
29+ < th data-type ="string "> Имя </ th >
3030 </ tr >
3131 </ thead >
3232 < tbody >
3333 < tr >
3434 < td > 5</ td >
35- < td > John </ td >
35+ < td > Вася </ td >
3636 </ tr >
3737 < tr >
3838 < td > 2</ td >
39- < td > Pete </ td >
39+ < td > Петя </ td >
4040 </ tr >
4141 < tr >
4242 < td > 12</ td >
43- < td > Ann </ td >
43+ < td > Женя </ td >
4444 </ tr >
4545 < tr >
4646 < td > 9</ td >
47- < td > Eugene </ td >
47+ < td > Маша </ td >
4848 </ tr >
4949 < tr >
5050 < td > 1</ td >
51- < td > Ilya </ td >
51+ < td > Илья </ td >
5252 </ tr >
5353 </ tbody >
5454 </ table >
5959 if ( e . target . tagName != 'TH' ) return ;
6060
6161 let th = e . target ;
62- // if TH, then sort
63- // cellIndex is the number of th:
64- // 0 for the first column
65- // 1 for the second column, etc
62+ // если ячейка TH, тогда сортировать
63+ // cellIndex - это номер ячейки th:
64+ // 0 для первой колонки
65+ // 1 для второй и т.д.
6666 sortGrid ( th . cellIndex , th . dataset . type ) ;
6767 } ;
6868
7171
7272 let rowsArray = Array . from ( tbody . rows ) ;
7373
74- // compare(a, b) compares two rows, need for sorting
74+ // compare(a, b) сравнивает два ряда, колбэк для метода sort
7575 let compare ;
7676
7777 switch ( type ) {
8787 break ;
8888 }
8989
90- // sort
90+ // сортировка
9191 rowsArray . sort ( compare ) ;
9292
9393 tbody . append ( ...rowsArray ) ;
Original file line number Diff line number Diff line change 2525 < table id ="grid ">
2626 < thead >
2727 < tr >
28- < th data-type ="number "> Age </ th >
29- < th data-type ="string "> Name </ th >
28+ < th data-type ="number "> Возраст </ th >
29+ < th data-type ="string "> Имя </ th >
3030 </ tr >
3131 </ thead >
3232 < tbody >
3333 < tr >
3434 < td > 5</ td >
35- < td > John </ td >
35+ < td > Вася </ td >
3636 </ tr >
3737 < tr >
3838 < td > 2</ td >
39- < td > Pete </ td >
39+ < td > Петя </ td >
4040 </ tr >
4141 < tr >
4242 < td > 12</ td >
43- < td > Ann </ td >
43+ < td > Женя </ td >
4444 </ tr >
4545 < tr >
4646 < td > 9</ td >
47- < td > Eugene </ td >
47+ < td > Маша </ td >
4848 </ tr >
4949 < tr >
5050 < td > 1</ td >
51- < td > Ilya </ td >
51+ < td > Илья </ td >
5252 </ tr >
5353 </ tbody >
5454 </ table >
5555
5656 < script >
57- // ...your code ...
57+ // ...ваш код ...
5858 </ script >
5959
6060</ body >
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ importance: 4
22
33---
44
5- # Sortable table
5+ # Сортировка таблицы
66
7- Make the table sortable: clicks on ` <th> ` elements should sort it by corresponding column .
7+ Сделать сортировку таблицы: при клике на элемент ` <th> ` должна происходить сортировка соответствующего столбца .
88
9- Each ` <th> ` has the type in the attribute, like this :
9+ Каждый элемент ` <th> ` имеет атрибут data- type:
1010
1111``` html
1212<table id =" grid" >
@@ -32,12 +32,12 @@ Each `<th>` has the type in the attribute, like this:
3232</table >
3333```
3434
35- In the example above the first column has numbers, and the second one -- strings. The sorting function should handle sort according to the type .
35+ В примере выше первая колонка содержит числа, а вторая -- строки. Функция сотрировки должна это учитывать, ведь числа сортируются иначе чем строки .
3636
37- Only ` "string" ` and ` "number" ` types should be supported .
37+ Сортировка должна поддерживать только типы ` "string" ` и ` "number" ` .
3838
39- The working example :
39+ Работающий пример :
4040
4141[ iframe border=1 src="solution" height=190]
4242
43- P.S. The table can be big, with any number of rows and columns .
43+ P.S. Таблица может быть большой, с любым числом рядов и столбцов .
You can’t perform that action at this time.
0 commit comments