Possible to use HTML instead of JSON for server-side processing?

Possible to use HTML instead of JSON for server-side processing?

kryakrya Posts: 11Questions: 2Answers: 0
edited June 2019 in Free community support

I'd really like to be able to offer developers one method of rendering, and still be able to use server side processing.

At the moment, I have an HTML table that outputs and it ultimately works with and and without JavaScript. DataTables is setup to use AJAX and server-side processing. But for things like action buttons (View, Edit, etc), I'm using a render method in the JS, as well as special formatting in the initial HTML. A lot of logic ends up in two places.

It would be super ideal in some cases to be able to render an HTML table, and use that in the AJAX payload instead of JSON... I've searched for about a week and it's hard to find this info. Is there an official method that supports this, or even a hack?

Answers

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Hi @kyra ,

    There's no official way of doing that, but you should be able to do a hack. If you look at the last example on the page for ajax.dataSrc, you can modify the data returned by the server. If you want the server to always return HTML, you could then parse it in ajax.dataSrc, get it in the JSON format required for serverSide and return that. The protocol is discussed here.

    Cheers,

    Colin

  • kryakrya Posts: 11Questions: 2Answers: 0

    Wow, my entire comment was deleted when I tried adding a [[ ... some kind of markdown parser bug?

  • kryakrya Posts: 11Questions: 2Answers: 0
    edited June 2019

    But thanks for the tip @colin !

    That does seem to be the way to do it. Still running into other issues, like it hangs on "Processing..." (with no console errors) when trying to do any operations, even though it does load the HTML via AJAX, etc. The first page loads and renders successfully, and the other pages are the same format.

    I wonder if it's something to do with the callback() being in the $.get() request. Not sure if you got an email alert with the contents of my first reply, but it's disappeared from the thread and had some code in it.. If it did come into your email, if you're able to post it just so it's not lost, that'd be awesome :)

  • colincolin Posts: 15,118Questions: 1Answers: 2,583
    edited June 2019

    Odd on the markdown, I just tried it, and it seems OK, maybe gremlins in the works. I get notified if there's a comment on a thread I've participated in, but it's only an alert to say there's a comment, it doesn't send the comment unfortunately.

    With the hanging "Processing...", it normally does that when the returned data from the ajax.data isn't properly formed - it would be worth running it through a JSON parser just to ensure it's valid.

This discussion has been closed.