그리드 서치 기능이 있길래 아이디어를 참고해서
수정, 가공해서 올려봄
공통함수는 전부 제외
// 전역 변수 설정
var objForm; // 부모 화면
var objTab; // 부모 창 Tab Object 설정
var bMultiGridYn = false; // 다중 그리드 여부
var loopCnt = 0; // 반복 횟수
this.searchFlag = false; // 검색 플래그
this.findText = false; // 검색된 텍스트 플래그
// 검색 버튼 클릭 시 호출되는 함수
this.btn_Search_onclick = function(obj, e) {
var objGrd = this.gfn_FindGridObject(objTab.tabpages[objTab.tabindex].form); // 현재 활성화된 탭의 그리드 객체를 찾음
var objDs = objGrd.getBindDataset(); // 그리드에 바인딩된 데이터셋
var pre_selecttype = objGrd.selecttype; // 이전 선택 타입
var findRow = -1;
var findCell = -1;
// 이벤트 활성화
objGrd.set_enableevent(true);
objDs.set_enableevent(true);
// 검색어가 있을 경우
if (this.gfn_IsNull(sFindData)) {
this.gfn_InitGridNoDataText(objGrd); // 검색어가 없으면 그리드 초기화
} else {
// 검색어를 대소문자 구분 없이 처리하기 위해 한 번만 대문자로 변환
var searchText = sFindData.toUpperCase();
// 그리드에서 검색
for (var i = 0; i < objDs.rowcount; i++) {
for (var iLoop = 0; iLoop < objGrd.getCellCount("body"); iLoop++) {
var cellText = objGrd.getCellText(i, iLoop);
if (cellText && cellText.toUpperCase().indexOf(searchText) > -1) {
this.findText = true;
findRow = i;
findCell = iLoop;
break;
}
}
if (this.findText) break;
}
}
// 텍스트를 찾았으면 해당 셀로 이동
if (this.findText) {
this.fn_moveGridCell(objGrd, findRow, findCell); // 그리드 셀 이동
} else {
// 검색 기록 초기화
this.initSearchText(objGrd);
this.fn_moveGridCell(objGrd, 0, 0); // 첫 번째 셀로 이동
}
// 필터 해제 (한 번만 호출)
this.ds_GridCss.filter("");
this.ds_OrgGridCss.filter("");
// 검색되지 않은 경우, 첫 번째 행으로 이동
if (!this.findText) {
objGrd.selectRow(0);
}
objGrd.redrawExprCell("body");
};
// 그리드 객체를 찾는 함수
pForm.gfn_FindGridObject = function(objForm) {
var arrComp = objForm.components;
var nLength = arrComp.length;
for (var i = 0; i < nLength; i++) {
var comp = arrComp[i];
if (comp instanceof nexacro.Div && this.gfn_IsNull(comp.url)) {
var grid = this.gfn_FindGridObject(comp.form);
if (grid) return grid;
} else if (comp instanceof nexacro.Tab) {
for (var j = 0; j < comp.tabpages.length; j++) {
if (this.gfn_IsNull(comp.tabpages[j].url)) {
var grid = this.gfn_FindGridObject(comp.tabpages[j].form);
if (grid) return grid;
}
}
} else if (comp instanceof nexacro.Grid) {
return comp;
}
}
return null;
};
// 검색된 텍스트가 없을 경우, 그리드에 "No Data" 텍스트 표시
this.gfn_InitGridNoDataText = function(objGrd) {
objGrd.set_text("No Data");
};
// 그리드 셀 이동 함수
this.fn_moveGridCell = function(objGrd, row, cell) {
if (row >= 0 && cell >= 0) {
objGrd.selectCell(row, cell); // 특정 셀로 이동하는 로직
}
};
// 검색 텍스트 초기화
this.initSearchText = function(objGrd) {
objGrd.clearSearchText(); // 검색 텍스트 초기화
};
// 그리드 저장 초기화 함수
this.initSaveGridDs = function(objGrd) {
// 그리드 데이터를 초기화하고 저장할 준비
objGrd.clearData(); // 데이터셋 초기화
objGrd.reset(); // 그리드 상태 초기화
// 데이터 새로 로드하는 로직 추가 가능 (예: objGrd.loadData())
trace("Grid data has been cleared and reset.");
};