Buttons Disappear after adding ajax:"..." data source

Buttons Disappear after adding ajax:"..." data source

daniegloydaniegloy Posts: 35Questions: 12Answers: 5

Buttons Show when i use html data.

$(document).ready(function() {
 var table = $('#example').DataTable( {
        lengthChange: false,
        buttons: true
    } );
 
    table.buttons().container()
        .insertBefore( '#example_filter' );
});

</script>

but when i want to use ajax data source, the buttons disappear.

$(document).ready(function() {
 var table = $('#example').DataTable( {
        lengthChange: false,
        buttons: true,
        ajax: "setData.php",
           columns: [...............]

    } );
 
    table.buttons().container()
        .insertBefore( '#example_filter' );
});



This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,508Questions: 1Answers: 10,471 Site admin
    Answer ✓

    You need to use initComplete to insert your buttons if you are using an asynchronous initialisation.

    Allan

  • daniegloydaniegloy Posts: 35Questions: 12Answers: 5

    Thank You Allan. It works Perfect. Is it Possible to appendto(); the default position of the table? What is the id for the default button position. I have tried (id="example_length") as appendto("#example_length"); but doesnt show, it does work in any other id element outside the table. Is it possible to display the buttons in default position?

  • daniegloydaniegloy Posts: 35Questions: 12Answers: 5
    Answer ✓

    OK Found it, Thanks.

    .appendTo('#example_wrapper .col-sm-6:eq(0)');
    
    
  • Fil6718Fil6718 Posts: 4Questions: 1Answers: 0

    I have the same problem. I didn't know how to use initComplete to insert my buttons.
    Di you have example to insert button.

  • daniegloydaniegloy Posts: 35Questions: 12Answers: 5
    edited November 2016

    var table = $('#example').DataTable( {
    stripeClasses: [ 'strip1', 'strip2'],
    ajax: "setData.php",
    lengthMenu: [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
    initComplete: function( settings, json ) {
    table.buttons().container().appendTo('#UserHead');
    },
    select: true,
    "bJQueryUI": true,
    order:[0,'des'],
    columns: [

  • Fil6718Fil6718 Posts: 4Questions: 1Answers: 0

    Thanks a lot but I didnt arrive to make it run....
    I create a new question to have help.

This discussion has been closed.