File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
2023-06-22
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
$(document).ready(function(){
//타이틀 select 선택 이벤트
$('[data-group]').on('change', '.field-selector', function() {
var group = $(this).closest('[data-group]').data('group');
var selectedFields = [];
var isDuplicate = false;
// 타불 객체 가져오기
var $objTabul = fn_utils_getTabulator();
console.log('$objTabul : ', $objTabul);
if($objTabul.getData().length < 1){
alert('데이터 입력 후 선택해 주세요.');
$(this).val("");
return false;
}
// 중복체크
$('[data-group="' + group + '"] .field-selector').each(function() {
var selectedField = $(this).val();
if (selectedField) {
if (selectedFields.includes(selectedField)) {
alert("중복된 필드를 선택할 수 없습니다.");
$(this).val(""); // 중복 필드를 선택한 경우 빈 값으로 초기화
isDuplicate = true;
return false; // 반복문 종료
}
selectedFields.push(selectedField);
}
});
//
updateTableFields($objTabul, group);
// 필드가 휴대폰이면 열 중복체크
if($(this).val() == 'phone'){
fn_phoneDupl($objTabul);
}
});
function fn_phoneDupl($objTabul){
var phoneFields = $objTabul.getData().map(row => row.phone);
if(phoneFields.length < 1){ return false; }
var uniquePhones = new Set();
var duplicatePhones = [];
phoneFields.forEach(phone => {
if (uniquePhones.has(phone)) {
duplicatePhones.push(phone);
} else {
uniquePhones.add(phone);
}
});
$('#rowDupCnt').text(duplicatePhones.length);
if (duplicatePhones.length > 0) {
alert("중복된 휴대폰 번호가 있습니다: \n" + duplicatePhones.join(", "));
} else {
// alert("중복된 phone 필드 값이 없습니다.");
}
}
/*
* 타이틀 select 선택할때마다 실행해서
* 데이터테이블 필드값 수정
*/
function updateTableFields($objTabul, group) {
var currentData = $objTabul.getData();
var columns = [
{formatter: "rowSelection", titleFormatter: "rowSelection", clipboard: false, hozAlign: "center", headerHozAlign: "center", headerSort: false, cellClick: function(e, cell) {
cell.getRow().toggleSelect();
}}
];
var fieldMapping = [];
$('[data-group="' + group + '"] .field-selector').each(function(index) {
var selectedField = $(this).val();
// ASCII 문자 코드 사용 - 65=A, 66=B ...
var field = String.fromCharCode(65 + index);
if (selectedField) {
columns.push({title: field, field: selectedField, hozAlign: "center", headerHozAlign: "center", editor: "input", width: 125, validator: ["maxLength:100", "string"]});
fieldMapping.push(selectedField);
} else {
columns.push({title: field, field: field, hozAlign: "center", headerHozAlign: "center", editor: "input", width: 125, validator: ["maxLength:100", "string"]});
fieldMapping.push(field);
}
});
var updatedData = currentData.map(row => {
var newRow = {};
fieldMapping.forEach((field, index) => {
newRow[field] = row[Object.keys(row)[index]] || "";
});
return newRow;
});
$objTabul.setColumns(columns);
$objTabul.setData(updatedData);
}
});