Confused about server side processing

Confused about server side processing

jnedzeljnedzel Posts: 28Questions: 4Answers: 0

I'm trying to understand the interface for server side processing, but I just can't follow the documentation. I'm trying to understand the sent parameters, but I'm lost. Looking at the documentation here:

https://datatables.net/manual/server-side

I understand things like start, and length. I expect that those will translate to an URL of the form:

http://localhost:9000/v2/egenes/Whole_Blood?draw=1&start=0&length=10

That is clear. But I'm completely lost when it comes to the "columns[i]" fields. What in the heck are these? Can someone provide me with a concrete example showing what is sent to the server? I've looked at the example here:

https://datatables.net/examples/server_side/simple.html#

but I just can't figure out what is sent to the server.

Answers

  • jnedzeljnedzel Posts: 28Questions: 4Answers: 0

    Using a JavaScript debugger, I've looked at the created URL and decoded it, which answers some questions, but adds more. The partial URL from the example is:

    https://datatables.net/examples/server_side/scripts/server_processing.php?draw=5&columns[0][data]=0&columns[0][name]=&columns[0][searchable]=true&columns[0][orderable]=true&columns[0][search][value]=&columns[0][search]

    But it looks as the the columns[?][name] parameter is empty. Is that to be expected? Are the column indicies only based on how they are ordered in the JavaScript? In other words, it appears to me that columns[0] is "First name", and therefore the server needs to know this as well, so if the client changes the column ordering it breaks the server. Or am I missing something vital here?

  • allanallan Posts: 63,360Questions: 1Answers: 10,448 Site admin

    But it looks as the the columns[?][name] parameter is empty. Is that to be expected?

    Yes - unless you use columns.name to give it a name. I wouldn't bother!

    Are the column indicies only based on how they are ordered in the JavaScript?

    They are based on the order of the columns in the HTML. If you were to reorder them, then they would change.

    it appears to me that columns[0] is "First name", and therefore the server needs to know this as wel

    Correct - the columns[?][data] parameter that is sent can be used to determine what data DataTables expects for that column. That is easier to understand when using object based data, like in this example.

    Allan

  • jnedzeljnedzel Posts: 28Questions: 4Answers: 0

    Allan:

    Thanks, I get it now.

    I'm a bit disappointed in the interface. It is convoluted and forces me to build two different REST interfaces -- one solely for DataTables and a second one for external collaborators. I would prefer an interface that uses column names, not the columns[?] syntax. I realize that won't happen anytime soon, but perhaps in a future version you could revisit this interface.

    Jared

  • allanallan Posts: 63,360Questions: 1Answers: 10,448 Site admin

    You could use preXhr or ajax.data to modify the data that is submitted to suit your needs.

    The DataTables server-side processing parameters are very much designed with the needs of DataTables data request in mind - which is a fairly specific problem domain. I'm not sure what a generic solution would be as most simple paging options would require all of the data that DataTables does.

    Allan

  • jnedzeljnedzel Posts: 28Questions: 4Answers: 0

    Allan:

    ajax.data is proving easy to use. I really don't want the interface of my REST service to be dependent upon the ordering of the columns in the presentation, so this allows me to specify the columns by name and thus remove that coupling.

    Thanks again for pointing me to ajax.data.

This discussion has been closed.