How to get current datatable request

How to get current datatable request

ShaNicShaNic Posts: 5Questions: 2Answers: 0

Hi everyone,

I'm new with Datatables.

I'm using this library in an Angular App using server-side.

I do something like this for my table ::

 this.dtOptions = {
      pagingType: 'numbers',
      serverSide: true,
      processing: true,
      dom: 'tlip'
      ajax: {
        url: myServerUrl/people',
        type: 'GET'
},
      },
      columns: [{ data: name}]
};

i want to get the end of the request of the current displaying table (filters,..). (Part of the request after "/people")
Is it possible to get and display it in console this part of the request ( draw=1&column... ) ?

Thanks !
Nick

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    No, there isn’t a way to get the inprogress Ajax call. What is the intention here? If you want to get the data that DataTables is sending to the server you can use the preXhr event.

    Allan

  • ShaNicShaNic Posts: 5Questions: 2Answers: 0

    Hi Allan,

    I found this :

    .dtInstance.then((dtInstance: DataTables.Api) => {
          console.log(dtInstance.ajax.params());
        });
    

    But now, when I want to use the result of dtInsance.ajax.params() in a function, i deserialize json with JSON.stringify(dtInstance.ajax.params) but i have

    myrequest/{draw:1,colum: ....}
    

    I want string.

    Ty
    Nick

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    You want the JSON object as a string? Use JSON.stringify(...)`.

    Allan

  • ShaNicShaNic Posts: 5Questions: 2Answers: 0

    Hi,

    I just found my soluce!

    i should use

    jQuery.param(dtInstance.ajax.params())
    

    Thanks for ur time and ur help !

This discussion has been closed.