Formatting Ajax data

Formatting Ajax data

j_sykj_syk Posts: 3Questions: 0Answers: 0
edited January 2012 in General
I'm playing around with populating my datatables with AJAX data. Trying to an ajax source instead of converting dynamically rendered html. (IMO a loading icon over the table is better than a browser loading icon for impatient people)

I'm wondering if there is an easy way to interject the resulting value into html formatting instead of just the face-value:
For example I want every value in the 3rd column to be wrapped in a VALUE or I want the 4th column to be link

Does that make sense? And is the functionality there already? Alternatively, I'm working on just making the JSON pre-formatted. Can you comment on if there is any escaping that would mess that up?

Replies

  • morrtymorrty Posts: 29Questions: 6Answers: 0
    I had asked this yesterday as I did the exact same thing. I was using dynamically generated DOM and when the records got up near 3k, the page load was horrendous. I switch to JSON/AJAX and it is instant now, especially with defer rendering. Unfortunately nobody responded and I ended up using pre-formatted JSON. Here's a free bump because I too would like to see if there is a way built into DataTables to do this.
  • matbeardmatbeard Posts: 22Questions: 0Answers: 0
    That's pretty straight-forward. You need to use the fnRender function described here: http://datatables.net/ref

    There's also an example here: http://datatables.net/release-datatables/examples/advanced_init/column_render.html
  • morrtymorrty Posts: 29Questions: 6Answers: 0
    Perfect! Thanks matbeard.

    Another question, will this affect the page rendering time more if we do it this way or if we were to do it server side before passing the json? Is this function affected by the "bDeferRender" option?
  • j_sykj_syk Posts: 3Questions: 0Answers: 0
    thanks matbeard! This is exactly what i was looking for. I figured it was built in somewhere!

    This morning I finished the formatting the json serverside. In my case it seems to be the same speed as the plain data. Either way, it's too slow for my liking.

    Maybe when I get the json faster, i'll compare serverside vs clientside formatting speeds. I'm the only developer, so in this case I'm not concerned about who can access what formatting where (i.e. frontend vs backend developers)
  • morrtymorrty Posts: 29Questions: 6Answers: 0
    I changed over my pre-formatted JSON to use "fnRender" instead and noticed no significant difference in rendering speed.

    Thanks again!
This discussion has been closed.