팡이네

.html

tr 태그는 포커스가 가능한 태그가 아니기 때문에 tabindex 속성 필요

1
2
3
4
5
...
<tr #trOrder tabindex="0">
    <td>...</td>
</tr>
...

.ts

1
2
3
4
5
6
7
import { ElementRef, QueryList, ViewChildren } from '@angular/core';
...
@ViewChildren('trOrder') trList: QueryList<ElementRef>;
...
setFocus(index) {
    this.trList.get(index).nativeElement.focus();
}

typescript, angular

 

문자열 표시 파이프

//--------------------------------------
// 문자열 표시 파이프
//--------------------------------------
/**
 * 문자열 형식 표시
 * options {
 *     replace: %s를 문자열로 변환하여 표시,
 *     pre:  문자열 앞에 표시
 *     post: 문자열 뒤에 표시
 *     limit: 지정한 길이만큼 표시
 * }
 * 사용법)
 *     {{ null | string : { post: '년' } }} => null
 *     {{ '2021' | string : { post: '년' } }} => '2021년'
 *     {{ '2021' | string : { replace: '(%s년 리모델링)' } }} => '(2021년 리모델링)'
 *     {{ 25 | string : { replace: '(지상 %s층)' } }} {{ 8 | string : { replace: ' / 지하 %s층' } }} => '지상 25층 / 지하 8층'
 *     {{ 25 | string : { replace: '(지상 %s층)' } }} {{ null | string : { replace: ' / 지하 %s층' } }} => '지상 25층'
 */
@Pipe({ name: 'string' })
export class StringPipe implements PipeTransform {
    transform(value: number | string, options?: { replace: string, pre: string, post: string, limit: number }): string {
        if (value) {
            let result: string = null;
            if (options?.replace) {
                result = options?.replace.replace('%s', ''+ value);
            } else {
                result = ((options?.pre) ? options?.pre : '') + value + ((options?.post) ? options?.post : '');
            }
            
            if (options.limit && result.length > options.limit) {
                result = result.slice(0, options.limit) +'...';
            }
            return result;
        } else {
            return null;
        }
    }
}

List 다중 컬럼 정렬

Java2021. 5. 21. 08:55

List 에 대하여 다중 컬럼 정렬을 하고자 할 때

 

//
export class Test {
    String name;
    Integer age;
    Integer score;
}

List list = ...;

// 점수순으로 정렬
list.sort( (a, b) -> a.getScore().compareTo(b.getScore()) );

// 점수순, 나이순으로 정렬
Collections.sort(list, Comparator.comparing(Test::getScore)
            .thenComparing(Test::getAge));
//

출처

https://stackoverflow.com/questions/4258700/collections-sort-with-multiple-fields

 

Collections.sort with multiple fields

I have a list of "Report" objects with three fields (All String type)- ReportKey StudentNumber School I have a sort code goes like- Collections.sort(reportList, new Comparator<Report>() { @

stackoverflow.com

내림차순(역순) 정렬

public class TempDTO {

	private Integer order;
    private String name;
    ...
}

list.sort(Comparator.comparing(TempDTO::getOrder, Comparator.reverseOrder()));