【问题标题】:update on change by ajax in yii gridview更新 yii gridview 中 ajax 的更改
【发布时间】:2015-03-26 14:58:19
【问题描述】:

我的数据库中有一个简单的表 tbl_task,具有以下属性:

  • id int auto_increment
  • 描述 varchar
  • 完整的布尔值

现在我创建了一个网格视图。完整属性的值由复选框显示。应该有可能更改完整属性的值。如果这样做,它应该将更改保存在数据库中。同时,gridview 每 3 秒从数据库中获取最新记录。

我尝试过修改gridview js文件,但是没有用。

有人知道如何解决我的问题吗?

非常感谢。

【问题讨论】:

    标签: javascript php ajax yii cgridview


    【解决方案1】:

    这应该不是很难完成。

    1) 为了每 3 秒更新一次网格,使用 javascript setInterval 并调用网格的更新方法:

    jQuery('#grid_id_here').yiiGridView('update');
    

    2) 在完整列中,将其设置为"type" => "raw",然后将其设置为"value",类似于"<input type='checkbox' onclick='mark_complete('.$data->id.')'>"

    3) 定义一个完成任务的javascript函数

    function mark_complete(id) {
    // 1. make here a ajax call that updates the task's complete field
    // 2. on the success of that ajax call place again the update command to update the grid
    }
    

    【讨论】:

    • 谢谢。我已经使用 selectionchanged 属性完成了它并调用了一个 javascript 函数
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 2014-05-22
    • 2011-10-05
    • 2014-09-05
    相关资源
    最近更新 更多