Update cells

Update cells

djonepldjonepl Posts: 3Questions: 2Answers: 0

Hi All,
I am stuck oh so stuck, I successfully created a table and loaded all content using server side processing. Everything was done using the example here: https://datatables.net/examples/data_sources/server_side.html

The script loads 6 columns with data, first column has ID number that correspond to names in a different table. I am stuck on how do i render those ID numbers in to names from another mysql table.
Below is my script, Ive tried rendering with $.ajax but it does not return the variables.

Column 0 contain the ID numbers, I also have scrip that returns only name by id.

Thanks.

var oTable = $('#sorting-advanced').dataTable({
    'processing': false,
    'serverSide': true,
    'ajax': './inc/MainTable.php',
    'sPaginationType': 'full_numbers',
    'sDom': '<"dataTables_header"lfr>t<"dataTables_footer"ip>',
    'aoColumnDefs': [ {
    'bSortable': false, 'aTargets': [ 6 ]},
    {
    'aTargets': [ 6 ],
    'mData': '6',
    'mRender': function ( data, type, full ) {
            return '<a href="#'+data+'" class="button compact icon-gear">Edit</a>';
    }
    },
    {
    'aTargets': [ 3 ],
    'mData': '3',
    'mRender': function ( data, type, full ) {
        if ( data === '1') {
            return '<td class="align-center"><small class="tag green-bg">YES</small></td>';
        } else {
            return '<td class="align-center"><small class="tag red-bg">NO</small></td>';
        }
    }
    },
    {
    'aTargets': [ 0 ],
    'mData': '0',
    'mRender': function ( data, type, full ) {

    $.get( "./inc/GetTableDetails.php?get=SysName&sid="+data, function( data ) {
        return data;
    });
    }
    }
    ]
});

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    Answer ✓

    The best way to do it would be to load the additional data in the JSON data - i.e. add a join to your server-side processing script to get that data.

    Using Ajax in columns.render I would suggest is not a good idea. Firstly you would need to make it synchronous so it can return the required data, and secondly that would make the whole page's rendering unbelievably slow.

    Allan

  • djonepldjonepl Posts: 3Questions: 2Answers: 0

    Allan,

    Thanks for the reply, the JOIN statment works much better. I guess i just needed to take a break and get some sleep. This morning i noticed i was doing it "ass backwards". I did some more googling and found this gentleman's customized script https://emranulhadi.wordpress.com/2014/06/05/join-and-extra-condition-support-at-datatables-library-ssp-class/

    As you mentioned before the way i was doing it it was going to overload the entire system.

    Thanks again.

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin

    Nice - thanks for the link. I hadn't seen that one before!

    Allan

This discussion has been closed.