Change feature parameters after initialize the table

Change feature parameters after initialize the table

iuliandumiuliandum Posts: 70Questions: 0Answers: 0
edited December 2009 in General
Hello all!
It's possible to change feature parameters (i.e. aaSortingFixed, aaSorting) after intialize the table?
Thank's!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi iuliandum,

    You can change the 'feature' parameters (i.e. bProcessing, bSort etc) after initialisation, but you can change the more general parameters such as aaSorting etc. What you need to do is grab the DataTables settings object for the table in question ( oTable.fnSettings() ) and then modify the required parameter - this isn't documented, so the best way is probably to look at the source code.

    If you want to change just aaSorting, then probably best to use the API function fnSort ( http://datatables.net/api#fnSort ). aaSortingFixed doesn't have an API function thought - although it would perhaps be a good idea to have a plug-in one ( http://datatables.net/development/api ).

    Regards,
    Allan
  • iuliandumiuliandum Posts: 70Questions: 0Answers: 0
    Thank you Allan for reply. I'll study the issue.
    Iulian
  • iuliandumiuliandum Posts: 70Questions: 0Answers: 0
    Hi Allan!

    I resolved that problem (change the 'feature' parameter [aaSortingFixed] after initialisation), but only change in jquery.dataTables.js file.
    I added this function:
    [code]
    this.fnSortFixed = function( aaSortFixed )
    {
    var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
    oSettings.aaSortingFixed = aaSortFixed;
    _fnSort( oSettings );
    };
    [/code]

    and to use it have to only call this: [code] oTable.fnSortFixed([[ 1, 'asc' ]]) [/code]

    I don't know yet to write a Api function. Maybe you will added this function in next version.
    Thanks for this jewel application!
    Iulianum
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited December 2009
    Hi Iulianum,

    Thanks for posting back - looks like your got the internal API functions nailed :-).

    To make it into a plug-in API function is actually very easy, all you need to do is this (before you initialise your DataTable):

    [code]
    $.fn.dataTableExt.oApi.fnSortFixed = function(oSettings, aaSortFixed)
    {
    oSettings.aaSortingFixed = aaSortFixed;
    oSettings.oApi._fnSort( oSettings );
    };
    [/code]
    A possible enhancement might be to slice() the array that is passed in, in case it is changed later on by some other logic (although this could be intentional and possibly quite useful :-) ).

    Regards,
    Allan
  • dadodado Posts: 17Questions: 0Answers: 0
    edited June 2010
    Hi Allan,

    i have a question about this solution. Itried it with 1.6.2 and get an error message that there is no oSettings.oApi_fnSort. I looked with firebug and there are a lot of _fn.. functions but no _fnSort.

    Can you please help me?

    Best regards
    Dado
This discussion has been closed.