AliHichem / AliDatatableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities
MIT License
112 stars 71 forks source link

how to use datatables advanced options with js functions #173

Open greg606 opened 8 years ago

greg606 commented 8 years ago

Is it possible to use more advanced options like this code:

$(document).ready(function() {
    $('#example').DataTable( {
        "columnDefs": [
            {
                // The `data` parameter refers to the data for the cell (defined by the
                // `data` option, which defaults to the column being worked with, in
                // this case `data: 0`.
                "render": function ( data, type, row ) {
                    return data +' ('+ row[3]+')';
                },
                "targets": 0
            },
            { "visible": false,  "targets": [ 3 ] }
        ]
    } );
} );

At the moment it collides with twig.

sfauch1 commented 8 years ago

@greg606 I was searching for the exact same thing this morning because I wanted to use the aoColumnDefs option. Here's what I ended up doing in twig.

Hope this helps

{{ datatable({
'id' : id,
'js' : {
'destroy' : true,
'sAjaxSource' : path(ajaxSource),
'dom': '<"pull-right"ri><t><"pull-right"p>',
'iDisplayLength' : 15,
'bProcessing' : false,
'aoColumnDefs': [
   { targets: [0], visible: false},
   { targets: '_all', visible: true }
],
'fnPreDrawCallback': 'function( e ) {
                if($("#modal-lookup-suppliers").hasClass("in")||$("#modal-lookup-customers").hasClass("in")){
                    $("#modal-loading").modal("show");
                }
            }',
'fnDrawCallback': 'function( e ) {
               $("#modal-loading").modal("hide");
            }'
}
}) }}
greg606 commented 8 years ago

@sfauch1 Thanks, I will check it ;)