ajax.data option does not work when I'm using a function that returns an object.

ajax.data option does not work when I'm using a function that returns an object.

jstuardojstuardo Posts: 104Questions: 41Answers: 0
edited April 2020 in Free community support

Hello, according do documentation (https://datatables.net/reference/option/ajax.data), this code should work when initializing datatable

               ajax: {
                    url: myURL,
                    type: "POST",
                    data: {
                        function(d) {
                            return $.extend({}, d, {
                                'fechaInicio': $('#rangoFechas').data('daterangepicker').startDate,
                                'fechaTermino': $('#rangoFechas').data('daterangepicker').endDate
                            });
                        }
                    }
                },

When the datatable is created and calls the URL, data passed is an object, and not both parameters individually (fechaInicio, fechaTermino).

What is wrong here?

Regards
Jaime

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.