render called twice

render called twice

NoooooBNoooooB Posts: 9Questions: 3Answers: 0
edited January 2015 in Free community support

hi
i have this code , table have just 4 rows but alert for ENTRY is called 8 times.... i should put ajax call that give me html code in the same place of alert. ( sorry for my orrible english).

var table=jQuery('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "/server_processing.php",
     "columnDefs": [ {
            "targets": 7,
            "data": null,
            "defaultContent": "<div class='btn-group'>   <button type='button' class='btn btn-default'  >Default</button><button type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown'> <span class='caret'></span>  <span class='sr-only'>Toggle Dropdown</span> </button> <ul class='dropdown-menu' role='menu'>  <li><a href='#'>Action</a></li><li><a href='#'>Another action</a></li>  <li><a href='#'>Something else here</a></li>  <li class='divider'></li>  <li><a href='#'>Separated link</a></li> </ul></div>"
        }, {
            "targets": 0,
            "data": null,
            "defaultContent": "<?php echo $check ?>"
        },
        {
             "render": function ( data, type, row ) {
                    
                    if(row[4]!= null)
                    {
                    var dividi=row[4];
                    
                    var div=row[4].split(',');
                    var text="";
                for (i = 0; i < div.length; i++) { 
                    text += "<option>"+div[i] + "</option>";
                }
                return "<select>"+text+"</select>";
                    }
                    else return "no cat";
                    
                    
                },
                "targets": 4
            },
            {
             "render": function (  row ) {
                         
                                      
                          alert("ENTRY ");           
             return "PINO";     
                    
                },
                "targets": 5
            }

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Yes, the columns.render method is called every time DataTables requests data from the data source - this is intentional and desirable.

    Allan

  • NoooooBNoooooB Posts: 9Questions: 3Answers: 0

    i not understand why twice for just a request :

    more simple example with 4 rows so i needs just 4 requests data:

    var table=jQuery('#example').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": "/server_processing.php",
    "columnDefs": [
    {
    "render": function ( data, type, row ) {

                   return " TRY"
    
                },
                "targets": 4
            }]
    

    why 8 TRY?

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    Likely DataTables needs to request the data multiple times for local caches of the various data types it holds. That could possibly be streamlines when server-side processing is enabled, but it is an optimisation that would see little end benefit (not to say it shouldn't be done, it just isn't a priority atm with other things needing to be done first).

    Allan

  • NoooooBNoooooB Posts: 9Questions: 3Answers: 0

    ty

This discussion has been closed.