112 lines
3.8 KiB
JavaScript
112 lines
3.8 KiB
JavaScript
/*
|
|
* 공통 UTIL 함수
|
|
*/
|
|
|
|
var _jxcelEactiveCustom = {
|
|
getEaColumnIndex : function (columnName) {
|
|
const columns = this.options.columns;
|
|
for (var i = 0; i < columns.length; i++) {
|
|
const column = columns[i];
|
|
if (column.name == columnName) {
|
|
return i;
|
|
}
|
|
}
|
|
},
|
|
getEaColumnName : function (index) {
|
|
var column = this.options.columns[index];
|
|
return column.name;
|
|
},
|
|
getEaCellValue : function (row, columnName) {
|
|
const col = this.getEaColumnIndex(columnName);
|
|
const cellId = jexcel.getColumnNameFromId([col, row]);
|
|
return this.getValue(cellId);
|
|
},
|
|
eaClearData : function () {
|
|
this.setData([{}]);
|
|
return this;
|
|
},
|
|
eaAutoResize : function (div_id) {
|
|
// window에 resize 이벤트를 바인딩 한다.
|
|
const _grid = this;
|
|
$(window).bind('resize', function() {
|
|
var totalWidth = $('#' + div_id).width();
|
|
var columns = _grid.options.columns;
|
|
/*
|
|
* 윈도우 사이즈가 1150일 경우 작은 minWidth로 지정
|
|
*/
|
|
var smallWindow = totalWidth < 1150;
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
var column = columns[i];
|
|
if (smallWindow && Number.isInteger(column.minWidth)) {
|
|
_grid.setWidth(i, column.minWidth);
|
|
} else if (!smallWindow) {
|
|
_grid.setWidth(i, column.maxWidth);
|
|
}
|
|
}
|
|
|
|
// 번호 컬럼 길이 50 기본 설정
|
|
var othersWidth = 50;
|
|
var resizeColumnCount = 0;
|
|
for (var i = 0; i < columns.length; i++) {
|
|
var column = columns[i];
|
|
if (column.type == 'hidden') {
|
|
continue;
|
|
}
|
|
if (!column.resize && Number.isInteger(column.width)) {
|
|
// 가변 컬럼이 아닌 경우
|
|
othersWidth += column.width;
|
|
} else {
|
|
// 컬럼길이가 가변으로 정해 진 경우
|
|
resizeColumnCount++;
|
|
}
|
|
}
|
|
|
|
if (resizeColumnCount == 0) {
|
|
return;
|
|
}
|
|
|
|
// 가변 컬럼의 길이는 전체 넓이에 나머지 컬럼의 길이를 뺀 후 가변 컬럼의 수로 나눈 값이 된다.
|
|
var resizeColumnWidth = (totalWidth - othersWidth) / resizeColumnCount;
|
|
for (var i = 0; i < columns.length; i++) {
|
|
var column = columns[i];
|
|
if (column.resize) {
|
|
if (resizeColumnWidth < column.minWidth) {
|
|
_grid.setWidth(i, column.minWidth);
|
|
} else {
|
|
_grid.setWidth(i, resizeColumnWidth);
|
|
}
|
|
} else {
|
|
if (smallWindow && Number.isInteger(column.minWidth)) {
|
|
_grid.setWidth(i, column.minWidth);
|
|
} else if (!smallWindow) {
|
|
_grid.setWidth(i, column.width);
|
|
}
|
|
}
|
|
}
|
|
|
|
var gridTotalWidth = 0;
|
|
for (var i = 0; i < columns.length; i++) {
|
|
var column = columns[i];
|
|
gridTotalWidth += column.width;
|
|
}
|
|
}).trigger('resize');
|
|
return _grid;
|
|
},
|
|
setEaRowData : function (index, rowData) {
|
|
try {
|
|
var gridData = this.getJson()
|
|
gridData[index] = rowData;
|
|
this.setData(gridData);
|
|
} catch (e) {
|
|
console.log('setEaRowData error : ' + e);
|
|
}
|
|
}
|
|
}
|
|
|
|
function JexcelEactiveCustom(element, options) {
|
|
var _jexcel = jexcel(element, options);
|
|
$.extend(_jexcel, _jxcelEactiveCustom);
|
|
return _jexcel;
|
|
}
|