我在RoR上使用dhtmlxGrid。我有一个复选框和一个“onCheck”事件,每次选中复选框时都会激活该事件。
<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>
当我选中任何复选框时,“警报”世界正常。我现在要做的是,当选中复选框时,自动更改单元格“状态”和“批准日期”中的值。该复选框名为“已批准”,当人们点击“已批准”复选框时,我希望使用当前日期自动更新名为“已批准日期”的单元格,并将“状态”更改为“已批准”。
我不知道如何在网格单元格中存储新值。我怎么能这样做,是否可能?
答案 0 :(得分: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
}