How can I change the number of entries shown based on the number of records returned?

How can I change the number of entries shown based on the number of records returned?

jjstewardjjsteward Posts: 3Questions: 1Answers: 0
edited July 2014 in Free community support

I would like to change the number of rows displayed based on the number of records returned. Specifically, if the number of records in my table is less than 10 than I want to show 10 records. If the number of records is between 11-25, I want to show 25 records. IF the number is between 26-50, I want to show 50 and if the number of records is greater than 50 I want to show 100.

I've looked into using the fnPreDrawCallback function, but I'm not sure how to access the number of records returned as the oTable.fnGetData().length is not available.

I've also looked into using the fnInitComplet function, but that gets called for each page in my table.

Any help would be appreciated.

Thanks!

Answers

  • jjstewardjjsteward Posts: 3Questions: 1Answers: 0
    edited July 2014

    ok, figured it out...

    "fnPreDrawCallback": function( oSettings ) {
                oTable = $("#datatable").dataTable();
                 if (oTable.fnGetData().length > 50 ) {
                       $('select', oSettings.aanFeatures.l).val( 100 ); 
                     oSettings._iDisplayLength = 100;
                 } else if (oTable.fnGetData().length > 25 ) {
                      $('select', oSettings.aanFeatures.l).val( 50 ); 
                      oSettings._iDisplayLength = 50;
                 }else if (oTable.fnGetData().length > 10 ) {
                      $('select', oSettings.aanFeatures.l).val( 25 ); 
                      oSettings._iDisplayLength = 25;
                 }
     },
    
  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin

    Heh - messy! Good to see you have a work around now though.

    Ultimately I want to have the server-side have the ability to return both the start point and the display length, but that will likely be a major version update rather than a bug fix release.

    Allan

This discussion has been closed.