Have a plugin use a Plugin function

Have a plugin use a Plugin function

talkitivewizardtalkitivewizard Posts: 30Questions: 0Answers: 0
edited March 2010 in General
How would you go about doing this. I have found that I am in need of combineing... or rather modifying... the fnReloadAjax plugin to use the fnStandingRedraw function as opposed to just regular redraw. Now I've gotten it to work by pasting the code from the StandingRedraw to ReloadAjax... but that's a very... hackish way to do things. Any suggestions? Works Beautifully btw...

[code]
jQuery.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback )
{
console.log("here");
if ( typeof sNewSource != 'undefined' )
{
oSettings.sAjaxSource = sNewSource;
}
console.log(oSettings.sAjaxSource);
this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;

oSettings.fnServerData( oSettings.sAjaxSource, null, function(json) {
/* Clear the old information from the table */
that.oApi._fnClearTable( oSettings );

/* Got the data - add it to the table */
for ( var i=0 ; i

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    "oSettings._iDisplayStart = before;" - that's the key thing. The code looks fine to me, and it's it's doing what you want - great! The API functions are there to be hacked to make them do what you are looking for... :-)

    I hadn't really considered doing a standing redraw with reload Ajax before, since it tends to be entirely new data, and thus one would want to start from the start. But perhaps you are using data which is just being updated, or some other place where this makes since. In which case, just setting _iDisplayStart before the draw will do nicely. The thing is that you will want DataTables to redo the filtering and sorting, and those functions automatically call the draw. So yes, this isn't perfect, in that there is a 'spare' draw in there (I'll have a think about how that might be avoided), but in practical terms, it should happen so fast that no one will see it...

    Allan
  • talkitivewizardtalkitivewizard Posts: 30Questions: 0Answers: 0
    edited March 2010
    Yeah in this case, We are having data update, and since multiple items can be effected by this one action (and I had very little development time on this one due to development costs), I needed this. If we were doing this right, It would be done all server-side, but it is so much easier to let Data Tables take over it when the Data-set isn't likely to get massive.

    It has been my experiance though, that DataTables handles really well, even under a few thousand records...

    And anything beats doing it the way we were doing it before (aka full page refreshes *hides in shame*).

    However, that didn't really answer my question I don't think...

    Is there a way to call a plugin function from a plugin?" Like make a plugin that has a dependency on another plugin? I haven't gotten into building plugins for this yet. I plan on actually trying to though, as I feel that this project is a wonderful thing and the love and joy it brings should be spread to the world :D
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Ah sorry - I rather glossed over that bit :-). The API functions should be a parameter of 'this' of other API functions, since they are executed in that scope:

    [code]
    $.fn.dataTableExt.oApi.fn1 = function ( settings, a ) {
    console.log( o, a );
    this.fn2( 2 );
    };

    $.fn.dataTableExt.oApi.fn2 = function ( settings, a ) {
    console.log( o, a );
    };

    $(document).ready(function() {
    var o = $('#example').dataTable();
    o.fn1(1);
    } );
    [/code]
    Note that DataTables adds the settings object for the 'inner' API call as well.

    Allan
This discussion has been closed.