custom event for select length

custom event for select length

EladElad Posts: 4Questions: 0Answers: 0
edited May 2012 in General
hi,

i think this is one of the must advanced plugin for jquery it's really good. thank you for it.

i have a question regarding custom event
http://datatables.net/release-datatables/examples/advanced_init/dt_events.html
i see here that 3 events can be bind, where can i get the full list?

my goal is to bind a custom event for pages_table_length changes.
i want to display only rows with .selected class.

thanks.

Replies

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Full list of events: http://datatables.net/docs/DataTables/1.9.1/DataTable.html#details_events

    Currently there isn't a custom event for length display change - however that's certain a good idea - I'll add it to my list of events to consider for future addition.

    Regards,
    Allan
  • EladElad Posts: 4Questions: 0Answers: 0
    edited May 2012
    thank you for the fast response,

    can you please advice on a hack for my task?

    i see that everything starts at this function:
    _fnFeatureHtmlLength

    i can add few line to it, is it a good idea (until the next version :))
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Have a look at this function, which is how DataTables does callbacks and events: https://github.com/DataTables/DataTables/blob/master/media/js/jquery.dataTables.js#L4710 . Although the easiest way is just to call $().trigger.

    Allan
  • EladElad Posts: 4Questions: 0Answers: 0
    edited May 2012
    yes, i am reading it.

    i am doing something like this:
    [code]
    $('#exapmle).dataTable({
    "aLengthMenu": [[-1,10,50,100,-2], ["All",10,50,100,"Only Mark"]],
    "fnDrawCallback":function(o){
    if(o._iDisplayLength == -2){
    /* here i think i should call _fnDraw() with sorted array for my rows
    i am having trouble to understand where i should do the manipulations
    should be something like if($(this).hassClass('selected')) o.tbody.push(this);
    }
    */
    }
    });
    [/code]
  • EladElad Posts: 4Questions: 0Answers: 0
    edited May 2012
    so i modify in a very ugly way _fnDraw function.

    this is the modified function code.
    now when it's done i think i made a mistake hacking your code like this (sorry)
    i should have play with adding bind option and not mess this function.

    maybe if i will have more time in the future (i only had a couple of hours to play with it.)

    initialization:
    [code]
    $('#exapmle).dataTable({
    "aLengthMenu": [[-1,10,50,100,-2], ["All",10,50,100,"Only Mark"]]
    })
    [/code]

    core code:
    [code]
    function _fnDraw( oSettings )
    {
    var i, iLen, n;
    var anRows = [];
    var iRowCount = 0;
    var iStripes = oSettings.asStripeClasses.length;
    var iOpenRows = oSettings.aoOpenRows.length;

    /* Provide a pre-callback function which can be used to cancel the draw is false is returned */
    var aPreDraw = _fnCallbackFire( oSettings, 'aoPreDrawCallback', 'preDraw', [oSettings] );
    if ( $.inArray( false, aPreDraw ) !== -1 )
    {
    _fnProcessingDisplay( oSettings, false );
    return;
    }

    oSettings.bDrawing = true;

    /* Check and see if we have an initial draw position from state saving */
    if ( oSettings.iInitDisplayStart !== undefined && oSettings.iInitDisplayStart != -1 )
    {
    if ( oSettings.oFeatures.bServerSide )
    {
    oSettings._iDisplayStart = oSettings.iInitDisplayStart;
    }
    else
    {
    oSettings._iDisplayStart = (oSettings.iInitDisplayStart >= oSettings.fnRecordsDisplay()) ?
    0 : oSettings.iInitDisplayStart;
    }
    oSettings.iInitDisplayStart = -1;
    _fnCalculateEnd( oSettings );
    }

    /* Server-side processing draw intercept */
    if ( oSettings.bDeferLoading )
    {
    oSettings.bDeferLoading = false;
    oSettings.iDraw++;
    }
    else if ( !oSettings.oFeatures.bServerSide )
    {
    oSettings.iDraw++;
    }
    else if ( !oSettings.bDestroying && !_fnAjaxUpdate( oSettings ) )
    {
    return;
    }

    if ( oSettings.aiDisplay.length !== 0 )
    {
    var iStart = oSettings._iDisplayStart;
    var iEnd = oSettings._iDisplayEnd;

    //Added by Elad for custom event
    var bMakeCustomBody = false;
    if(iEnd == -2)
    {
    bMakeCustomBody = true;
    iEnd = oSettings.aoData.length; //we want to go thru all the TR's
    }
    //End Elad
    if ( oSettings.oFeatures.bServerSide )
    {
    iStart = 0;
    iEnd = oSettings.aoData.length;
    }

    for ( var j=iStart ; j
This discussion has been closed.