fnDrawCallback on the fly

fnDrawCallback on the fly

necrotosnecrotos Posts: 12Questions: 3Answers: 0
edited May 2011 in General
How can i use fnDrawCallback on the fly after i initialize the dataTable object ?

[code]
oTable = $("#table").dataTable();
oTable.fnDrawCallback = someCallback;
[/code]

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    If "someCallback" is a function you could just do "someCallback();" could you not?

    Allan
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Ah - thinking about it - do you mean how can you reassign fnDrawCallback on-the-fly? There isn't a public API for that - it's possible by using the DataTables settings object, but a little messy. You could call a function inside your someCallback and make that function the variable one?

    Allan
  • necrotosnecrotos Posts: 12Questions: 3Answers: 0
    edited May 2011
    hi Allan,

    okay i see, when i used oTable.fnSettings().fnInitComplete it solved. But when i used ajax processing with dataTable the problem is appear. The function is not defined. Take a look at my code:

    PHP Generate Code
    [code]
    $table = Admin_Api_Core::getInstance()->ajaxTableDisplay(array(
    'id' => 'listforum',
    'columns' => $this->_columnTitles,
    'dataTables' => array(
    'bJQueryUI' => true,
    'sPaginationType' => 'full_numbers',
    'aoColumns' => array(
    null,
    array('sWidth' => '10%'),
    null,
    array('sClass' => 'center', 'sWidth' => '5%'),
    null,
    array('bSortable' => false, 'bSearchable' => false, 'sClass' => 'center', 'sWidth' => '12%')
    ),
    'bProcessing' => true,
    'bServerSide' => true,
    'sAjaxSource' => $this->view->url(array('module' => 'admin', 'controller' => 'forums', 'action' => 'ajax'))
    )
    ));
    [/code]

    PHP Parsing code
    [code]
    $script[] = '';
    $script[] = '$(document).ready(function() {' . PHP_EOL;

    $script[] = 'oTable = $("#' . $id . '").dataTable(' . json_encode($params) . ');' . PHP_EOL;
    $script[] = 'oTable.fnSettings().fnInitComplete = renderButton;console.log(oTable.fnSettings())';

    $script[] = '});';
    [/code]

    i can't reference javascript function into json_encode value, that's way i need a public API for fnDrawCallback
  • necrotosnecrotos Posts: 12Questions: 3Answers: 0
    ~ Solved ~

    I solved that by using Zend_Json encoder function

    [code]
    $table = Admin_Api_Core::getInstance()->ajaxTableDisplay(array(
    'id' => 'listforum',
    'columns' => $this->_columnTitles,
    'dataTables' => array(
    'bJQueryUI' => true,
    'sPaginationType' => 'full_numbers',
    'aoColumns' => array(
    null,
    array('sWidth' => '10%'),
    null,
    array('sClass' => 'center', 'sWidth' => '5%'),
    null,
    array('bSortable' => false, 'bSearchable' => false, 'sClass' => 'center', 'sWidth' => '12%')
    ),
    'bProcessing' => true,
    'bServerSide' => true,
    'sAjaxSource' => $this->view->url(array('module' => 'admin', 'controller' => 'forums', 'action' => 'ajax')),
    'fnDrawCallback' => new Zend_Json_Expr('renderButton')
    )
    ));
    [/code]

    thx allan
This discussion has been closed.