3

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

当我选中任何复选框时,“警报”世界很好。我现在要做的是在选中复选框时自动更改单元格“状态”和“批准日期”中的值。该复选框称为“已批准”,当人们单击“已批准”复选框时,我希望名为“已批准日期”的单元格自动更新为当前日期,并将“状态”更改为“已批准”。

我不知道如何在网格单元格中存储新值。我该怎么做,可能吗?

4

1 回答 1

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
}
于 2013-10-28T23:00:21.717 回答