Old user and playing around with buttons - some questions

Old user and playing around with buttons - some questions

mihomesmihomes Posts: 165Questions: 23Answers: 0

I've been using datatables for awhile now and just came across the new buttons extension. In my project I have a LOT of buttons which do various things, but at the time had to hand code all of it. So, I am playing around with the buttons extension to see if there would be any benefit to changing my code. Few questions :

Using a simple example such as :

"buttons": [
    {
        text: 'Select All',
        className: 'btn-success',
        action: function ( e, dt, node, config ) {
            alert( 'Button activated');
        }
    },
    {
        text: 'Deselect All',
        className: 'btn-success',
        action: function ( e, dt, node, config ) {
            alert( 'Button activated');
        }
    },
    {
        text: 'Refresh',
        className: 'btn-success',
        action: function ( e, dt, node, config ) {
            alert( 'Button activated');
        }
    }
],

Buttons show fine and work great, BUT I notice they are all 'grouped together' with the parent class having 'dt-buttons btn-group'. Can we turn on/off the btn-group class? In my case there are times where I would like them grouped and others when I don't.

Finally, aside from being able to define and reuse buttons what benefit is there to using this method instead of the old way :

//load in the dom
$("#dtButtons").html('<button id="dtSelect" type="button" class="btn btn-success">Select All</button>');

//do something
$('#dtSelect').on('click', function () {
    ...some action
});

Lastly, the copy, print, csv, colvis, etc is what intrigued me. At the moment I only offer a csv download and did all the creation/downloading of it by hand rather than using tabletools. Problem is I use server-side and I noticed right off the bat all of those solutions only work for what is actually shown in the table just as I figured. Is there no way to add functionality for server-side here? We already have the ajax options defined so I would think it would be possible to pass the last table params (search, sort, etc) and get results no? In my case all of these are useless if I can't allow the viewer to copy/print/csv/etc anything more than the current page results.

Answers

  • allanallan Posts: 63,602Questions: 1Answers: 10,486 Site admin

    Just to confirm - this is with Bootstrap styling? I'm going to assume so in my reply below :-).

    Can we turn on/off the btn-group class?

    Not in an individual instance. A single Buttons instance is a group. If you want multiple groups you need multiple instances. See this example.

    Finally, aside from being able to define and reuse buttons what benefit is there to using this method instead of the old way

    Consistency with the rest of the DataTables API. You can do it with regular jQuery / DOM if you want :-).

    Is there no way to add functionality for server-side here?

    See this FAQ.

    Allan

  • mihomesmihomes Posts: 165Questions: 23Answers: 0

    Yeah, I had already noticed this in the docs. I guess I should have rephrased my question as it was intended to be more of a 'is there a chance this is supported down the road' type of question.

    With that said... is there? I haven't looked at the internal code or anything yet, but I would think the main pieces of the puzzle are pretty much there... ajax, search, sorting, etc. It seems as though a call (same as a draw) could be made with the only change being the limit - rather than a results limit for the page there is no results limit. In a way we need to do this in the server side script anyways to get the total results, total filtered, etc.

    By the way... congratulations on the addition to the family!

  • allanallan Posts: 63,602Questions: 1Answers: 10,486 Site admin

    is there a chance this is supported down the road' type of question.

    It isn't likely. As the FAQ suggests, client-side file creation when the data set is at the server-side just doesn't really make much sense to be honest. You'd be best having the file created by the server most likely.

    Allan

    p.s. Thanks :-)

This discussion has been closed.