tigrang / cakephp-datatable

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

Initialization with options #22

Closed shotokai closed 11 years ago

shotokai commented 11 years ago

Awesome Plugin. Many thanks!

I'm trying to figure out how to modify the Initialization code. For instance if I wanted full pagers, I would initialize with:

$(document).ready(function() {
    $('#example').dataTable( {
        "sPaginationType": "full_numbers"
    } );
} );

What is the correct way to do this using your plugin?

shotokai commented 11 years ago

After looking at the DataTableHelperI realized that the javascript options is the 3rd argument in DataTableHelper::render , so:

$js_options = array();
$js_options['sPaginationType'] = 'full_numbers';
echo $this->DataTable->render(null, array(), $js_options);

does the trick for the specific question I had. My question now is f I wanted to set these in the controller, could I?

xeongt commented 11 years ago

I'm trying to add a function for add checkboxes:

                            'aoColumnDefs' => array(

                                    'aTargets' => array(0),
                                    'fRender'  => 'function ( oObj ) {
                                                                return \'<input id="chkBox" name="chkBox" value="\'+ oObj.aData[0] +\'" type="checkbox" checked="" />\';
                                                            }'
                            )

but the function is output scaped and does not work, how can add a function ?

Thanks!

tigrang commented 11 years ago

@shotokai Yes (I think).

In your controller:

class MyController {
    public $helpers = array(
        'DataTable.DataTable' => array(
            'js' => array(
                'sPaginationType' => 'full_numbers',
            ),
        ),
    );
}

Apologies for the very, very late response.

tigrang commented 11 years ago

@xeongt That's an issue with json_encode not being able to encode functions.

What you can do instead is manually init the datatables and use the global dataTableSettings js var to add your fender function.

Use the console in your browser to see what dataTableSettings looks like, then you'll be able to add what you need to it, and finally call $('#mytable').dataTable(dataTableSettings['ModelName'])

If you have any more questions, open a new issue please. I'll try my best to respond quicker.

tigrang commented 11 years ago

Marking as closed. Re-open if it doesn't work @shotokai