Where The Streets Have No Name

동적으로 dataSet, Grid추가 본문

Developement/RIA

동적으로 dataSet, Grid추가

highheat 2007. 2. 23. 15:06
<script language=Javascript>
var glCount = 0;
   
function fncCreate(){   
   
    var oContainer = document.getElementById("spContainer");   
    var dsNode = document.createElement("object");
    var gridNode = document.createElement("object");   
       
    /* dataSet attribute setting */
    with(dsNode){
        classid="clsid:3267EA0D-B5D8-11D2-A4F9-00608CEBEE49";
        id="Tb_DataSet"+glCount;       
        dataid="data.csv";
    }
    oContainer.appendChild(dsNode);
    dsNode.reset();
   
    /* checkbox add */   
    var checkNode = document.createElement("<input type='checkbox' id='check"+glCount+"' name='chkDel' onClick='fncOnCheck(this)'>check"+glCount+"</input>");
    oContainer.appendChild(checkNode);
   
       
    /* grid attribute setting */
    with(gridNode){
        classid="clsid:1F57AEAD-DB12-11D2-A4F9-00608CEBEE49";
        id="Tb_Grid"+glCount;
        style.value="width:500;height:100px;";
        dataid="Tb_DataSet"+glCount;
        format = "<c> id=col01 name="+glCount+" width=100 </c>";         
    }
       
    oContainer.appendChild(gridNode);
    //alert(container.innerHTML);
    glCount++;   
}

function fncAllDelete(){
    var oContainer = document.getElementById("spContainer");   
   
    /* childNode의 끝에서부터 삭제 */       
    for(var i=oContainer.children.length-1; i >= 0; i--){                       
        var oChild = oContainer.children(i);
        oContainer.removeChild(oChild);
    }
    glCount = 0;
}
   
function fncOnCheck(arg){
    //alert(arg.id+":"+arg.checked);   
}   

function fncDelete(){   
    var chkDel = document.getElementsByName("chkDel");
    var oContainer = document.getElementById("spContainer");   
   
    /* 삭제 */       
    for(var i=0;i < chkDel.length;i++){           
        if(chkDel[i].checked){
            var tmp = chkDel[i].id;
            var num = tmp.substr(5,tmp.length);
            var oTarget = document.getElementById("check"+num);
            oContainer.removeChild(oTarget);       
            oTarget = document.getElementById("Tb_Grid"+num);
            oContainer.removeChild(oTarget);
            oTarget = document.getElementById("Tb_DataSet"+num);
            oContainer.removeChild(oTarget);       
        }
    }
}

</script>

<input type="button" value="create" OnClick="fncCreate()">
<input type="button" value="all delete" OnClick="fncAllDelete()">
<input type="button" value="delete" OnClick="fncDelete()">
<span id=spContainer>
</span>