Looking for an example usage of Buttons customize

Looking for an example usage of Buttons customize

ian1scottian1scott Posts: 2Questions: 1Answers: 0

I am trying perform a selective export the with Buttons export functionality. I am hoping to use one button for exporting either ALL rows or just the selected rows if some rows are selected. The description of the customize() function appears to be what I want to use but I can't seem to get it to work. What are the parameters the function takes and how are they used to filter the data.
Perhaps just a good example of usage will get me on my way?

Shown below is how I was trying to use it but it always results in an "undefined" export data set:

buttons: [ {
                    extend:     'csv',
                    text:       'CSV',
                    header:     true,
                    filename:   function(){
                        return 'Export_' + new Date().getTime();
                    },
                    customize: function(data, config){
                                    
                    var count = table.rows( { selected: true } ).count();
                    if (count > 0){
                              data = table.buttons.exportData( { selected: true } );
                    } else {
                              data = table.buttons.exportData();
                    }
                                    
            }
}]

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,767Questions: 1Answers: 10,721 Site admin
    Answer ✓

    The customize method isn't what you want here - its too late by that time. I guess it could be made to work, but I think it would be a lot of work.

    It probably needs a little change in this function. Check to see if any rows are selected, and if so, use the selected: true modifier. If not, then just allow it to select all. That should probably be a toggable option (default disabled).

    Nice idea!

    Allan

  • ian1scottian1scott Posts: 2Questions: 1Answers: 0

    Thanks for the lightning quick response, Allan!

    I'll go ahead and modify my local version of the code. Does this sound like an official feature you would be willing or looking to add in the future?

    Ian

  • allanallan Posts: 64,767Questions: 1Answers: 10,721 Site admin

    Yes - I think that would be a useful addition that others would benefit from as well.

    Allan

This discussion has been closed.