【问题标题】:Ignited Datatables edit_column call back function点燃的数据表编辑列回调函数
【发布时间】:2014-10-12 15:43:27
【问题描述】:

我正在使用“Vincent Bambico and Yusuf Ozdemir”编写的数据表库 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”检查函数是否存在时,找不到函数。我做了一些研究,我认为问题是由于我使用的类结构造成的,但我不确定如何解决这个问题。

【问题讨论】:

    标签: php jquery codeigniter datatables


    【解决方案1】:

    创建帮助文件包含你的方法 callback_date($date_created)
    然后在加载 helper 后,您可以使用 edit_column 或 add_column 中的方法

    【讨论】:

      【解决方案2】:

      我知道这个问题已经一岁了。但是我今天遇到了同样的情况,尽管我会在这里分享我的发现以及我如何解决同样的问题。希望能对某人有所帮助。

      我从 Github 下载了最新版本的 Ignite 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)');
      

      希望这会有所帮助:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-29
        • 2015-03-23
        • 1970-01-01
        • 1970-01-01
        • 2023-04-03
        相关资源
        最近更新 更多