2013-10-27 17 views
3

我在RoR上使用dhtmlxGrid。我有一個複選框和一個「onCheck」事件,每次選中該複選框時都會激活它。如果選中複選框更改單元格值 - RoR中的dhtmlxGrid

<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> 

當我檢查任何複選框時,「alert」世界正常。我現在想要做的是在複選框被選中時自動更改單元格「狀態」和「批准日期」中的值。該複選框稱爲「已批准」,當用戶點擊「已批准」複選框時,我希望名爲「批准日期」的單元格自動更新爲當前日期,「狀態」更改爲「已批准」。

我不知道如何在網格單元內存儲新的值..我怎麼能這樣做,這有可能嗎?

回答

2

你已經擁有你想要更新的ROWID,所以你只需要告訴網格設置你想要的列中的值,並標記行作爲更新您的數據處理器檢測改變

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

相關問題