Ignited Datatables编辑列回调函数

时间:2014-08-19 13:48:37

标签: php jquery codeigniter datatables

我正在使用由" Vincent Bambico和Yusuf Ozdemir编写的数据表Libray" https://github.com/IgnitedDatatables/Ignited-Datatables

我已查看此处提供的支持信息http://codeigniter.com/forums/viewthread/160896/

我在使用编辑列功能时遇到问题。

function paging()
{
    $this->load->helper('form');
    $this->load->library('Datatables'); 

    $this->datatables->select('id, name, visit_date, date_created, postcode, order_total, status')
        ->from('day_orders')
        ->edit_column('status','$1', 'callback_cap(status)')
        ->edit_column('date_created','$1', 'callback_date(date_created)');       
    echo $this->datatables->generate();

}

public function cap($i)
{
    return ucfirst($i);
}

public function date($i)
{
    return date('d-m-Y', $i);   
}

而不是输出到json字符串的数据,我得到的是我作为第三个参数输入的文本,所以" callback_date(date_created)"例如。不确定我做错了什么?任何想法?

编辑: 问题似乎是图书馆无法找到我的任何回叫功能。上面的代码示例都包含在一个类中。我已经尝试将回调函数放在几个不同的地方,包括lib文件中,但我还没有运气。

当我们通过" function_exists"来检查函数是否存在时没有找到任何功能。我已经完成了一些研究,我认为问题是由于我使用的课程结构,但我不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

我知道这个问题已经有一年了。但是我今天遇到了同样的情况,虽然我会在这里分享我发现的内容以及我如何修复同样的问题。它有望帮助某人。

我从Github下载了最新版本的Ignited Datatables库。

https://github.com/IgnitedDatatables/Ignited-Datatables

然后,我在以下blog中找到了此解决方案。虽然它有一些错误和问题,但我很容易通过自己修复并使其正常工作。

您需要做的是将回调函数作为辅助函数包含。

将此保存在application / helpers / my_datatable_helper.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/** 
*  edit_column callback function in Codeigniter (Ignited Datatables)
*
* Grabs a value from the edit_column field for the specified field so you can
* return the desired value.  
*
* @access   public
* @return   mixed
*/

if ( ! function_exists('check_status'))
{
    function check_status($status = '')
    {
        return ($status == 1) ? 'Active' : 'Inactive';
    }   
}

/* End of file MY_datatable_helper.php */
/* Location: ./application/helpers/MY_datatable_helper.php */ 

然后在你的控制器中,在调用edit_column方法之前,加载这个帮助器,如下所示。

$this->load->library('Datatables');
$this->load->helper('My_datatable_helper');

$this->datatables->edit_column('is_active','$1', '$this->test(is_active)');

希望这会有所帮助:)

相关问题