Get Datatable Ajax URL with all parameters

Get Datatable Ajax URL with all parameters

KhanaKhana Posts: 2Questions: 1Answers: 0

Hi everyone,

Into the Javascript code, I simply can't figure out how to get the whole URL of a Datatable Ajax call, with all the settings in it,

I want to get a string like that :
https://datatables.net/examples/server_side/scripts/objects.php?draw=2&columns[0][data]=first_name&columns[0][name]=&columns[0][searchable]=true&columns[0][orderable]=true&columns[0][search][value]=&columns[0][search][regex]=false&columns[1][data]=last_name&columns[1][name]=&columns[1][searchable]=true&columns[1][orderable]=true&columns[1][search][value]=&columns[1][search][regex]=false&columns[2][data]=position&columns[2][name]=&columns[2][searchable]=true&columns[2][orderable]=true&columns[2][search][value]=&columns[2][search][regex]=false&columns[3][data]=office&columns[3][name]=&columns[3][searchable]=true&columns[3][orderable]=true&columns[3][search][value]=&columns[3][search][regex]=false&columns[4][data]=start_date&columns[4][name]=&columns[4][searchable]=true&columns[4][orderable]=true&columns[4][search][value]=&columns[4][search][regex]=false&columns[5][data]=salary&columns[5][name]=&columns[5][searchable]=true&columns[5][orderable]=true&columns[5][search][value]=&columns[5][search][regex]=false&order[0][column]=0&order[0][dir]=asc&start=0&length=10&search[value]=k&search[regex]=false&_=1501262539441

Can anyone enlighten me?

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    You can use ajax.params() and ajax.url() to get the information. You could then parse the results to build the above string.

    Kevin

  • KhanaKhana Posts: 2Questions: 1Answers: 0

    Why should I parse the ajax.params() while Datatable do it itself to call the Ajax URL? Can't I retrieve this string without bothering to reconstitute it?

    (My goal is to update the browser's history after each Datatable Ajax call)

  • dtuser18dtuser18 Posts: 2Questions: 1Answers: 0

    I agree with Khana. The last ajax full URL could easily be provided by a built-in method (the core does that anyway). Could you please add this functionality?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    DataTables does't translate the data object, jQuery does that for us, via the $.param() method (at least, that's what I believe jQuery does internally).

    That said, why would you want to get the URL encoded parameters on the client-side? I curious about the use case, since it would be easier to use the API to get those values.

    Regards,
    Allan

  • picasso566picasso566 Posts: 4Questions: 1Answers: 0

    It's been over a year since the last comment, but I have the same use case.

    I'm running server-side with a json service. I want to use the same code that I use for generating the sql for the datatables response to process a completely deferent request.

    Example:
    I have a Datatable of Users
    in the xhr event of the datatable I want to fire off another call to get all the stats for all of the employees that were a result of the same filtering in the Datatables call. So if I filter the datatable on the User's age or something I want the stats to be filtered by age.

    If the stats service and the datatables service both work with the same server side datatables request and generate the same where clause server side, this would be very helpful.

    Right now, I trying to use the table.ajax.params and for the life of me I cannot get them to encode the same as datatables is.

  • picasso566picasso566 Posts: 4Questions: 1Answers: 0

    Now I feel like an idiot, you posted the solution right there:

    $.param(table.ajax.params())

This discussion has been closed.