2013-10-27 1 views
3

RoR에서 dhtmlxGrid를 사용하고 있습니다. 확인란과 체크 상자가 선택 될 때마다 활성화되는 이벤트 "onCheck"가 있습니다.확인란을 선택한 경우 셀 값 변경 - dhtmlxGrid in RoR

<script type="text/javascript" charset="utf-8"> 
     var grid = new dhtmlXGridObject("grid_here"); 
     grid.setImagePath("/images/dhtmlx/imgs/"); 
     grid.setHeader("Result, PatientID, Approved, Status, Approved Date"); 
     grid.attachHeader("#text_filter,#text_filter,#text_filter,#text_filter,#text_filter"); 
     grid.setColTypes("txt,ed,ch,co,ed"); 
     grid.setColSorting("str,str,str,str,date"); 
     grid.setInitWidths("100,100,*"); 
     grid.setSkin("dhx_skyblue"); 
     grid.init(); 
     grid.load("/approves/data"); 
     grid.attachEvent("onCheck",doOnCheckBoxSelected); 

     dp = new dataProcessor("/approves/dbaction.xml"); 
     dp.init(grid); 

     function doOnCheckBoxSelected(rID, cInd, state) 
     { 
      if (state=='1') 
       {alert("date approved");} 

     } 
    </script> 

체크 박스를 선택하면 "경고"세계 정상입니다. 지금하고 싶은 것은 체크 박스가 선택되면 셀 "Status"와 "Approved Date"의 값을 자동으로 변경하는 것입니다. 체크 박스는 "Approved"라고하고, "Approved"체크 박스를 클릭하면 "Approved Date"셀이 현재 날짜로 자동 업데이트되고 "Status"는 "Approved"로 변경됩니다.

그리드 셀 안에 새 값을 저장하는 방법을 모르겠다. 어떻게해야합니까? 가능합니까?

답변

2

이미 업데이트 할 ROWID, 그래서 당신의 dataprocessor이 변화를 감지하기 위해 업데이트 당신은 당신이 원하는 컬럼에 값을 설정하는 그리드를 이야기하고 행을 표시해야

function doOnCheckBoxSelected(rID, cInd, state){ 
    if (state=='1'){ 
     alert("date approved"); 
    } 
    var currentDate = new Date(); //This is just an example, here you can generate the Date in the format you wish. 
    /*Here goes the column index in which the date or status are... 
    In this case I'm assuming in the column 3 is the Status and in 4 the Date of approval, change them to your 
    real indexes*/ 
    grid.cells(rID,3).setValue('Approved'); 
    grid.cells(rID,4).setValue(currentDate); 

    dp.setUpdated(rID,true); //You tell your dataProcessor that the row was updated, so it mark the row as updated 
    return true; //if i recall correctly this is needed for the function to end correctly, maybe not 
} 
+0

고마워, 이미 "setValue"를 수행하고 거의 작동했지만 코드의 "dp.setUpdated()"부분이 누락되었습니다. – lbramos

관련 문제