Loading content into the datable on form submit

Loading content into the datable on form submit

huba_sbfhuba_sbf Posts: 16Questions: 6Answers: 1

Hey guys,

I would like to put my datatable "to work" only after I fill in some edit boxes (used as filters), not automatically when accessing my page. This is due to the large amount of data in my table which I don't want to load on initalisation as it's taking ages.
In my case I would like to add a date picker in order to display data of the selected day.
I believe it requires a form, an edit box and a submit button, plus changing the $(document).ready(function() into something else.
However, since I might be wrong, I would like to ask you if there is an example for this, on how to do it the "right" way?

Thank you.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    There isn't an example for that, but basically you wouldn't call the $().DataTable() method until you are ready to initialise the DataTable.

    Allan

  • huba_sbfhuba_sbf Posts: 16Questions: 6Answers: 1
    edited October 2016

    It might be basic, but can you please tell me how to call it, if I would like to call it, after clicking the submit button?
    Here is the example and my solution, but there might be a more elegant one:
    ```

    <?
    if ($_POST["date"] != '') {

    <?php > ... $(document).ready(function() { ... }); ... <? } ?> ``` ?>

    Thank you!

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓
    var table;
    
    $('#myButton').on( 'click', function () {
      if ( ! table ) {
        table = $('#myTable').DataTable();
      }
    } );
    
  • huba_sbfhuba_sbf Posts: 16Questions: 6Answers: 1

    Thank you!

This discussion has been closed.