tigrang / cakephp-datatable

JQuery DataTable plugin server-side processing component for CakePHP
47 stars 29 forks source link

How use it with query conditions #34

Closed brunokimuramon closed 11 years ago

brunokimuramon commented 11 years ago

my code:

public $components = array(
    'DataTable.DataTable' => array(
        'columns' => array(
            'Task.id' => array(
                'bSearchable' => 'plainSearch',
                'bSortable' => true
            ),                  
            'Task.inicio' => array(
                                    'bSearchable' => false,
                'bSortable' => true
            ),
            'Task.fim' => array(
                'bSearchable' => false,
                'bSortable' => true
            ),
            'Task.titulo' => array(
                'bSearchable' => 'plainSearch',
                'bSortable' => true
            )
        )
    )
);

public $helpers = array(
    'Js',
    'DataTable.DataTable'
);

public function index() {

    if ($this->request->is('ajax')) {

        $this->DataTable->paginate();

    }

}

I need put condition in my query, how can i do?

tigrang commented 11 years ago

$this->DataTable->settings['scope'] = array(); and $this->DataTable->settings['conditions'] = array();

brunokimuramon commented 11 years ago

Thanks, i used and it works:

        $this->DataTable->settings['Task'] = array(
            'conditions' => array(
                ...
            ),
        );

Now, i have associations defined in models and i want use "recursive = 1", how can i do it? Thanks again.

tigrang commented 11 years ago

Just set it after the conditions key.

brunokimuramon commented 11 years ago

Thanks! it works!

tigrang commented 11 years ago

No problem

sherwinrobles commented 11 years ago

I am trying to use condition based on if conditions.. but not working... no errors but the conditions is not working. what seems to be the problem? thanks.

//not working public function summary($biller_id = null) {

    if(!empty($biller_id)){
            $this->DataTable->settings['conditions'] = array('BillsTransaction.biller_id' => $biller_id);

    }

}

//working public function summary() {

            $this->DataTable->settings['conditions'] = array('BillsTransaction.biller_id' => 1);

}