utils_grid_setup-grid-multi-cell-copy.js

/**
 * 인수로 넘긴 그리드를 멀티 셀 복사 가능하도록 변경합니다 다음 세 가지 프로퍼티를 덮어씁니다.
 * selectchangetype,selectscrollmode, selecttype.
 *
 * @function setupGridMultiCellCopy
 * @param {nexacro.Form} form        넥사크로 폼
 * @param {nexacro.Grid} targetGrid  대상 그리드
 * @returns {boolean} 성공 시 true 반환
 * @memberof $f
 * @example
 * $f.setupGridMultiCellCopy(this, this.grd_main);
 *
 */
export function setupGridMultiCellCopy(form, targetGrid) {
    if ((!targetGrd) instanceof nexacro.Grid) return false;

    targetGrd.selectchangetype = "up";
    targetGrd.selectscrollmode = "select";
    targetGrd.selecttype = "multiarea";

    targetGrd.addEventHandler(
        "onkeydown",
        (obj, e) => {
            let clipValue = "";

            if (e.ctrlkey && e.keycode == 67) {
                let grdDatasetNm = obj.bindDataset;
                let clipValue = "";
                let vSep = "\r\n";
                let hSep = "    ";

                for (
                    var i = nexacro.toNumber(obj.selectstartrow);
                    i <= nexacro.toNumber(obj.selectendrow);
                    i++
                ) {
                    for (
                        var j = nexacro.toNumber(obj.selectstartcol);
                        j <= nexacro.toNumber(obj.selectendcol);
                        j++
                    ) {
                        let cellVal = obj.getCellValue(i, j);

                        if (cellVal === undefined || cellVal === null)
                            cellVal = "";

                        clipValue += cellVal;
                        clipValue += j < obj.selectendcol ? hSep : "";
                    }
                    if (i < obj.selectendrow) {
                        clipValue += vSep;
                    }
                }
                clipValue += "";

                system.clearClipboard();
                system.setClipboard("CF_TEXT", clipValue);
            }
        },
        form,
    );

    return true;
}