Service Side Processing return html

Service Side Processing return html

ankita_rorankita_ror Posts: 5Questions: 3Answers: 0

Hi,

I want to use server side processing for pagination. I have lot of data and n number of condition for rendering columns. My current code is working fine in simple html.I want to add datatable in that and ajaxify pagination. But problem i am facing is while clicking particular page it will return html (<tr><td><td>...</tr>) not JSON and because i have lot of condition to rendering columns and some table data consist html also. So it would be difficult to render JSON instead of HTML. Is any hacks in datatable so while doing server side processing, I can render/ replace tbody?
Referring this (https://datatables.net/examples/server_side/simple.html)

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @ankita_ror ,

    It would be expected that the server returns JSON. The best bet would be to look at the Ajax tabs on the link you posted, or look at this page here which defines the protocol expected in the response.

    Cheers,

    Colin

  • ankita_rorankita_ror Posts: 5Questions: 3Answers: 0

    Hi @colin ,

    Thanks for quick response. Is any way to activate current page in pagination?.
    Our code is in Ruby on rails and we have lot of tables in our application. So converting all in JSON would be difficult. Like Using Defer Loading (https://datatables.net/examples/server_side/defer_loading.html), I have loaded first page and by clicking on any other page, I just replaced tbody with new response.Now i just want to activate current page in ajax success. Is this possible?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @ankita_ror ,

    I suspect that will run into problems - it's forcing something to work in a way that it wasn't intended.

    You could just disable paging in the DataTables, and implement your own. You could have your buttons for "next" and "prev", and when pressed, they get the rows in any format you want. If success, you could either destroy or rows().remove() to remove the existing rows, and add your new data with rows.add() or just insert the tbody if that's what you get and reinitialise the table.

    Hope that helps,

    Colin

This discussion has been closed.