Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use datatables advanced options with js functions #173

Open
greg606 opened this issue Mar 17, 2016 · 2 comments
Open

how to use datatables advanced options with js functions #173

greg606 opened this issue Mar 17, 2016 · 2 comments

Comments

@greg606
Copy link

greg606 commented Mar 17, 2016

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
Copy link

sfauch1 commented Apr 21, 2016

@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
Copy link
Author

greg606 commented Apr 21, 2016

@sfauch1 Thanks, I will check it ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants