File tree Expand file tree Collapse file tree 3 files changed +32
-32
lines changed
2-ui/2-events/03-event-delegation/3-sortable-table Expand file tree Collapse file tree 3 files changed +32
-32
lines changed 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는 몇 번째 열인지를 나타내는 인덱스 값입니다.
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에 할당할 함수 compare(a, b)는 두 행을 비교하고 필요에 따라 정렬을 진행합니다.
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,42 +2,42 @@ 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> ` 속성엔 다음과 같이 데이터의 타입이 정의되어 있습니다.
1010
1111``` html
1212<table id =" grid" >
1313 <thead >
1414 <tr >
1515*!*
16- <th data-type =" number" >Age </th >
17- <th data-type =" string" >Name </th >
16+ <th data-type =" number" >나이 </th >
17+ <th data-type =" string" >이름 </th >
1818*/!*
1919 </tr >
2020 </thead >
2121 <tbody >
2222 <tr >
2323 <td >5</td >
24- <td >John </td >
24+ <td >일리야 </td >
2525 </tr >
2626 <tr >
2727 <td >10</td >
28- <td >Ann </td >
28+ <td >보라 </td >
2929 </tr >
3030 ...
3131 </tbody >
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+ 이 문제에선 ` '숫자' ` 와 ` '문자열' ` 타입만 다룬다고 가정하겠습니다 .
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