Usage of draw in datatables

Usage of draw in datatables

stackhellostackhello Posts: 4Questions: 2Answers: 0

I am well aware the usage of draw in server side processing of datatables. However, i am not clear how the response of "draw" parameter in json works. Does it automatically ensure that the Ajax returns from server-side processing requests are drawn in sequence by DataTables if the "draw" value is included in the response json? Or any additional logic is required for it to be drawn in sequence?

This question has an accepted answers - jump to answer

Answers

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

    The draw parameter (server-side processing) is just a sequence counter. It allows responses to come back out of order and DataTables will draw the correct page.

    For example:

    1. Draw=1 requested
    2. Draw=2 requested
    3. Draw=2 returned and drawn
    4. Draw=1 returned (ignored).

    This is done automatically by DataTables.

    Allan

  • stackhellostackhello Posts: 4Questions: 2Answers: 0

    Thanks for your reply. May i know is there any built-in way to get the draw number of the request on ajax response? or just simply asssign draw = request.draw in ajax return json value?

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    Answer ✓

    You could use xhr or ajax.json to get the JSON data from the last request and thus access the draw parameter. Why would you need to get it after the data is fetched?

    At the server-side it should just be draw = parseInt( input.draw ); (or however you access parameters on whatever server environment you are using). Make sure to cast it as an integer for security.

    Allan

This discussion has been closed.