3

Using ajax.relaod isn't updating the value that is being passed to the controller. The variables have the correct values each time when entering the function but I'm not sure how to get reload to also see/accept the updated variables. Do I need to destroy and rebuild the table each time?

if (!$.fn.DataTable.isDataTable('.workorder-table')) {
    $('.workorder-table').DataTable({
        "initComplete": function () {
            hidePleaseWait();
        },
        rowCallback: function (row, data, index) {
            --row classes added here based on data
        },
        columns: [
            { "data": "Facility", "name": "Facility", "title": "Facility" },
            { "data": "ShortDescription", "name": "ShortDescription", "title": "Short Description" },
            { "data": "Created", "name": "Created", "title": "Created" },
            { "data": "Completed", "name": "Completed", "title": "Completed" },
            { "data": "Status", "name": "Status", "title": "Status" }
        ],
        ajax: {
            url: "/Facility/WorkOrderSearch",
            type: "POST",
            data: { status: $('#Status').val(), facilityID: $('#FacilityID').val(), quickView: $('#QuickView').val() }
        },
        -- options here
    });
} else {
    $('.workorder-table').DataTable().ajax.reload(hidePleaseWait);
}
2
  • 3
    data should be a function, i.e data: function(d) { d.status: $('#Status').val() ,... } then it will be executed upon ajax.reload() Commented Jun 15, 2017 at 11:17
  • Perfect thank you. If you can turn it into an answer, I can accept it. Commented Jun 15, 2017 at 11:20

1 Answer 1

7

If data is turned into a function that can be executed

data: function(data) {
  data.status = $('#Status').val();
  data.facilityID = $('#FacilityID').val();
  data.quickView = $('#QuickView').val();
}

Then this function will be executed upon each request, i.e when ajax.reload() is called.

Sign up to request clarification or add additional context in comments.

2 Comments

Still applicable 7/27/18 - lifesaver! Is this a "datatables" thing, or a javascript in general thing? (making it a function to execute it each reload)
@SourceMatters, it is a DataTables enhancement of jQuery AJAX, I believe the code is found here, around line 3871 -> github.com/DataTables/DataTables/blob/master/media/js/… if data is a function the function is executed. jQuery AJAX does not support this (perhaps in a later version, but none I know of)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.