Disable On Load Ajax Call In Datatable

Disable On Load Ajax Call In Datatable

anemaanema Posts: 13Questions: 6Answers: 0

I am using DataTables 1.10.11 in my project to display some user data on the Page. I am Loading the table data from the server using Ajax call. My data table working fine without any issue. My Datatable:

$("#user_table").DataTable({
"destroy": true,
"order": [],
dom: "Bfrtip",
"bProcessing": false,
"bServerSide": false,
"searching": false,
"pageLength": 7,
"autoWidth": false,
"bAutoWidth": false, // Disable the auto width calculation
"sort": "position",
"stateSave": true,

    "ajax": {
        url: "Url/data",
        type: "GET",
        dataSrc: function (json) {

            $('#user_profile_box div.overlay').fadeOut();

            return json;
        }
    }
});

I don't want to load my datatable content from server on load of the page. I want my table to load if user click on load button. Is there any workaround for this issue??

Thank You!!!

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 2,068Questions: 0Answers: 377

    Hi @anema ,

    Take a look at this example here from a different thread, this demonstrates what you're after,

    Cheers,

    Colin

  • anemaanema Posts: 13Questions: 6Answers: 0
    edited June 15

    Hi Colin,

    Thanks for the solution, But in the above solution I need to write Entire Datatable Property 2times?
    1st at the time of initialization and 2nd while calling the ajax.
    "bProcessing": false,
            "bServerSide": false,
            "searching": true,
            "pageLength": 5,
            "autoWidth": false,
            "bAutoWidth": false, // Disable the auto width calculation 
            "sort": "position",
            "stateSave": true,
            "ordering": false,
            "deferLoading": false,
    "language": {
                "lengthMenu": "Display _MENU_ records per page",
                "zeroRecords": "No records available",
                "infoEmpty": "",
                "loadingRecords": "Loading...",
                "processing": "Processing..."
            },
    buttons: []
    
  • colincolin Posts: 2,068Questions: 0Answers: 377
    Answer ✓

    Hi @anema ,

    In that example you need to declare the table twice, but you could create an object that contains the initialisation settings which you then just refer it, something like this,

    Cheers,

    Colin

Sign In or Register to comment.