Ajax loading executed before the entire layout is completed

Ajax loading executed before the entire layout is completed

SorinSSorinS Posts: 1Questions: 1Answers: 0

Description of problem: I am using Datatables 2.1, with server-side ajax data loading. I want to create a select element in the topEnd section of the layout and use the selected option as a parameter for the ajax call. But when I load the page the value of the select element is undefined, because the layout code was not yet executed. Is there a way to postpone the ajax call until the entire layout is completed?

Answers

  • rf1234rf1234 Posts: 3,026Questions: 88Answers: 422

    I want to create a select element in the topEnd section of the layout and use the selected option as a parameter for the ajax call.

    I have a similar situation but I don't have the select element inside the data table's layout. If you have it outside the table's layout there shoud be no issues.

    Example: I am passing the startDate to the server for the ajax call which is based on a select field which is above the data table.

    var contractLogTable = $('#tblContractLog').DataTable( {
        dom: "Bfrltip",
        ajax: {
            url: 'actions.php?action=tblContractLog',
            type: 'POST',
            data: function ( d ) {   
                d.startDate = nMonthsAgo( $('#periodSelected').val() );
            }
        },
    
  • kthorngrenkthorngren Posts: 21,546Questions: 26Answers: 4,988

    If you are using server side processing, ie serverSide enabled, you might be able to use deferLoading. Once the option is selected then use draw() to fetch the page via ajax.

    Or if you want to initially load the data via ajax or are using client side processing then just send a default value if the select option is undefined.

    Kevin

Sign In or Register to comment.