UltraWebGrid에서 선택한 로우 삭제하는 방법

2008.02.04 13:05 개발언어/3rd Part
HOWTO:How to delete rows on the client in UltraWebGrid?
참고를 하였다

Summary

In order to delete rows on the client in javascript you need to use the javascript function: igtbl_deleteRow(gridName,rowID). First, be sure to allow the deletion itself by setting the AllowDeleteDefault property in the DisplayLayout object or AllowDelete on the specific band.

The function needs to be passed the name of the grid and the ID of the row you want to delete.

The following sample Javascript code would delete all rows on the client in a function.

function delete()
{
    //make sure that deletes are allowed
    igtbl_getGridById("UltraWebGrid1").AllowDelete=1;
    //get the first row in the grid
     var row=igtbl_getRowById("UltraWebGrid1r_0");
    //delete the first row in the grid
     igtbl_deleteRow("UltraWebGrid1","UltraWebGrid1r_0");
    //create a counter for the row id
     var cnt=0;
    //create a loop, if the row has a next sibling then we need to delete it
     while(row.NextSibling!=null)
     {
        //increment the counter for the next rowID
         cnt+=1;
        //get the row current row using the name of the grid and the row number from our counter so we can check it for a sibling
         row=igtbl_getRowById("UltraWebGrid1r_"+cnt)
        //finally delete that row,
         igtbl_deleteRow("UltraWebGrid1","UltraWebGrid1r_"+cnt);
}

All the selected rows within the grid can be deleted as well. For deleting selected rows, use the following function: igtbl_deleteSelRows(gridName).

igtbl_deleteSelRows("UltraWebGrid1");


이걸 참고하여서 선택한 로우만 삭제하게 바꾸었다.



우선 호출할 자바스크립트 버튼생성을 생성한다
[CODE]
<input type = "button" onclick ="SelectDeleteRow()" value ="선택한 ROW삭제" style="height: 32px" />
[/CODE]

코드부분은 이렇게 작성하였다

 function SelectDeleteRow()
 {  
     igtbl_getGridById("UltraWebGrid1").AllowDelete=1;
     var row = igtbl_getActiveRow("UltraWebGrid1").Element.id;  //현재 선택한 로우 id    
     igtbl_setActiveRow("UltraWebGrid1", igtbl_getElementById(igtbl_getActiveRow("UltraWebGrid1").Element.id) );
     igtbl_selectRow("UltraWebGrid1", row, true);      //also select the activerow in the grid
     igtbl_deleteSelRows("UltraWebGrid1");
 }



설명은 이렇다. 우선 ActiveRow를 선택하면 그 아이디를 받아서 setActiveRow로 세팅을 한다.
igtbl_deleteSelRows함수를 사용하여 선택한 로우를 삭제하면된다.

선택한 로우에 대한 색깔지정이나 이런건 생략하였다.
신고