일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- php
- 후기
- 일상
- 아이패드
- 아이폰
- 유료
- 게임
- 가사
- Monument Valley
- great forest
- Monument
- 시사회
- 모뉴먼트 밸리
- 감상
- 모뉴먼트
- 핑크
- 공략
- 아이폰게임
- goblin sword
- 강추
- 잡담
- 추천
- JavaScript
- 맛집
- 카이로소프트
- 영화
- jQuery
- 아이러브니키
- 레고
- Pink
- Today
- Total
잡담소장소
[javascript] bootstrap-table export csv 문제 본문
bootstrap-table.com을 통해 grid 생성 후
csv로 export를 하는데 data가 undefined 일 경우 '- 로 데이터가 나오는 문제가 확인되었다
Bootstrap Table · An extended table to the integration with some of the most widely used CSS frameworks. (Supports Bootstrap, S
Bootstrap Table An extended table to the integration with some of the most widely used CSS frameworks. (Supports Bootstrap, Semantic UI, Bulma, Material Design, Foundation) Currently1.18.1
bootstrap-table.com
data가 undefined의 경우는 bootstrap-table에서 - 로 바꿔서 보여주는데
formatter를 통해 - 로 변경했을 경우도 '- 로 csv에서 노출되고 있었다
bootstrap-table 의 export는 tableExport.jquery.plugin 을 사용하고 있고 exportOption을 그대로 차용한다
해서 해당 코드를 확인하게 되었는데
// defaults option
...
preventInjection: true, // Prepend a single quote to cell strings that start with =,+,- or @ to prevent formula injection
...
preventInjection 옵션에서 발견한 하이픈..
해당 코드를 좀더 확인해보니 preventInjection 함수에서 - 가 '- 로 변경되는 것을 확인할 수 있었다
...
if (dataString instanceof Date)
result = defaults.csvEnclosure + dataString.toLocaleString() + defaults.csvEnclosure;
else {
result = preventInjection(csvValue);
result = replaceAll(result, defaults.csvEnclosure, defaults.csvEnclosure + defaults.csvEnclosure);
if (result.indexOf(defaults.csvSeparator) >= 0 || /[\r\n ]/g.test(result))
result = defaults.csvEnclosure + result + defaults.csvEnclosure;
}
...
function preventInjection (str) {
if (str.length > 0 && defaults.preventInjection === true) {
var chars = '=+-@';
if (chars.indexOf(str.charAt(0)) >= 0)
return ('\'' + str);
}
return str;
}
...
preventInjectin 옵션을 false로 주면 해결
csv의 경우 colspan, rowspan이 불가능하여 excel로 다운로드 추가해보았는데 파일이 정상적으로 다운로드 되지 않아 디버깅해보니 아래와 같은 메세지가 노출되었다
saveAs is not a function
FileSaver.js 추가하여 해결
github.com/eligrey/FileSaver.js/issues/253
'Study ;3' 카테고리의 다른 글
react + react-router tutorial (0) | 2021.06.02 |
---|---|
[java] @Transactional 과 custom advisor 사용 시 문제 (0) | 2021.01.15 |
[java] PKIX path building failed (0) | 2020.12.23 |
[javascript] jquery-typeahead 적용기 (0) | 2020.12.02 |
<a>의 download 속성 이슈 (0) | 2020.11.30 |