Loading data into a cell of a table via AJAX

Loading data into a cell of a table via AJAX

TonyatdcuTonyatdcu Posts: 3Questions: 0Answers: 0
edited February 2013 in DataTables 1.9
Guys,

I'm evaluating DataTables for a project I'm working on and have made excellent progress in the last day or so. I've loading large database tables into the DataTables object using AJAX and it's working beautifully.

However, one column of the table needs to come from another computed table lookup. So I need to load a cell with this data using an AJAX lookup. I tried doing this using the fnRender

"fnRender": function ( o, val ) {
jQuery.ajaxSetup ({ cache: false });
var row = $(this).closest('tr');
$(row).load('dt_getactivity.php');
}

but this doesn't work.

Can you guys shed some light on how to dynamically load this content?

Thanks in advance,

Tony

Replies

  • TonyatdcuTonyatdcu Posts: 3Questions: 0Answers: 0
    Allan,

    The Debug code is ovukug
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    Hi Tony,

    fnRender isn't executed with the scope of the element, so `$(this)` does not result in a jQuery instance with the table cell - fundamentally that is why this isn't working at the moment.

    However, before moving to a solution, more generally - these two points seem incompatible to me:

    > loading large database tables

    > load a cell with this data using an AJAX lookup

    That sounds scary to me! If you have 10'000 rows for example, that's 10'000 Ajax requests. Even if you only have 100 rows, that's still enough to make your sever seriously sweat!

    I'd suggest looking for a different solution to this problem if that is possible. What does dt_getactivity.php do? is it something that could be loaded once and then some processing done in Javascript? Or better yet, can you merge the data from dt_getactivity into your data feed?

    Regards,
    Allan
  • TonyatdcuTonyatdcu Posts: 3Questions: 0Answers: 0
    Good point! I've redesigned the table structure so that we don;t have a dynamically created cell.

    Thanks for the advice,

    Tony
This discussion has been closed.