Adding extra functionality to the createdRow callback

Adding extra functionality to the createdRow callback

jLinuxjLinux Posts: 981Questions: 73Answers: 75

I was playing around with a plugin that would need to interact with rows as they are created, but without interfering with the existing createdRow callback if it exists.

Is there a way to add a 2nd createdRow callback somehow?

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited November 2015

    I notice the aoRowCreatedCallback inside the DT Settings object is an array with a function (if the createdRow was set), so Im trying to add an anonymous function to it, heres the JSFiddle, but it doesn't seem to work.. But I'm close! I can feel it!

    The error is

    Cannot read property 'apply' of undefined

    But its odd, because I can see both have the apply(): http://d.pr/i/JLqR

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Tried the following:

    $.fn.dataTable.ext.feature.push( {
        fnCreateTr: function ( oSettings, iRow, nTr, anTds ) {
            console.debug('test');
        }
    } );
    

    Which didnt work, but I didnt expect it to, was a total shot in the dark from looking through the DT JS, heh

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited November 2015

    This works, but im sure theres a better way, if not, COOL!

    ( function( window, document, $, undefined ) {
      $( document ).on('init.dt', function(e, dtSettings) {
        console.log('settings',dtSettings);
        var newFunction = function(row, data, dataIndex){
          console.debug('# createdRow ============');
          console.debug('row',row);
          console.debug('data',data);
          console.debug('dataIndex',dataIndex);
          console.debug('# =======================');
        };
        dtSettings.oApi._fnCallbackReg(dtSettings, 'aoRowCreatedCallback', newFunction, 'user');
      });
    })( window, document, jQuery );
    

    Got that from looking around the DT JS code, I found the line:

    _fnCallbackReg( oSettings, 'aoRowCreatedCallback', oInit.fnCreatedRow,        'user' );
    

    Then looked at the _fnCallbackReg function, and it was self-explanitory from there

    Not sure what the sName is though?

    And is there a way to prioritize them?

This discussion has been closed.