簡體   English   中英

點火數據表edit_column回調函數

[英]Ignited Datatables edit_column call back function

我正在使用“ 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”檢查函數是否存在時,找不到函數。 我進行了一些研究,我認為問題是由於我使用的類結構引起的,但我不確定如何解決問題。

創建幫助文件包含您的方法callback_date($ date_created)
然后在加載幫助程序后,您可以在edit_column或add_column中使用method

我知道這個問題已經一歲了。 但是我今天面臨着同樣的情況,盡管我將在這里分享我發現的內容以及如何解決同一問題。 希望它將對某人有所幫助。

我從Github下載了最新版本的Ignited Datatables庫。

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

然后,我在以下博客中找到了該解決方案。 盡管它存在一些錯誤和問題,但我很容易自己將其修復並使其正常運行。

您要做的就是將回調函數作為輔助函數包括在內。

將此保存在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)');

希望這可以幫助 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM