New react version!!! how to create a serverside ajax query?

New react version!!! how to create a serverside ajax query?

willgartwillgart Posts: 1Questions: 1Answers: 0
edited September 11 in Free community support

Hi,

just found that datatables.net has now a React component available.
any sample on how to setup it for a serverside ajax access?

in JQuery I'm using a code like this:

 table = $("#dataTable").DataTable({
....
                ajax: {
                        url: surl, // URL of your Azure Function
                        type: 'POST', // Use POST method to send data
                        headers: { "Authorization": "Bearer " + lbearer },
                        data: function (data) {
                                data.length = 5000;
                                data.search = { "value": "", "regex": false, "fixed": [] };
                                data.draw = 1;
                                return JSON.stringify(data);
                        },

                },
});

how to create this code in React?
I see the ajax property in the DataTable component, but not sure how to implement it.

any sample?
thanks.

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    Probably easiest to have it as a property:

    let ajax = {
      url: surl,
      type: 'POST',
      // ...
    };
    
    return (
      <DataTable ajax="{ajax}" ...
    );
    

    You could do it inline with the JSX, whatever you prefer.

    Allan

Sign In or Register to comment.