• mirlemko

    (@mirlemko)


    Hello,

    it would be nice if you could limit the display “standard lines per page” for certain tables e.g. only 25 max., or 50 max. lines.

Viewing 1 replies (of 1 total)
  • Plugin Author wpDataTables

    (@wpdatatables)

    Hello.
    We are sorry, but we are not sure we fully understand what you meant by this.
    If you mean to remove/add available options from ‘default rows per page’ in tables,

    we don’t have a solution to have a different setting for individual tables, at the moment there is only a workaround to have the same setting for all tables.

    It can be done by adding a hook to your active Theme or child Theme’s functions.php file.

    With this solution, it will not be affected by plugin updates

     since it would pull the function from the Theme itself.

    For example, if you need the same options for all tables,

    add this hook: “wpdatatables_filter_table_description” to the active Theme’s or child Theme’s functions.php :


    add_filter( 'wpdatatables_filter_table_description', 'verse_show_entries', 10, 3 );
    function verse_show_entries( $object, $table_id, $wpDataTableOBJ ){  
      $object->dataTableParams->aLengthMenu = array(    
        array(             
                   10,     
                       25,    
                        50,     
                       75,       
                     100    
        ),      
      array(     
                   10,    
                    25,     
                   50,      
                  75,    
                    100  
          )  
      );  
      return $object;
    }

    ( This example removes the “ALL” option from the number of rows selection dropdown, but you can modify it to change/add options you need)

    Or, if you just need it for one specific table, you can pass table ID, as a parameter of the function, like this :

    add_filter( 'wpdatatables_filter_table_description', 'verse_show_entries', 10, 3 );
    function verse_show_entries( $object, $table_id, $wpDataTableOBJ ){
        if ($table_id == 1){
           $object->dataTableParams->aLengthMenu = array(
               array(
                   10,
                   25,
                   50,
                   75,
                   100
               ),
               array(
                   10,
                   25,
                   50,
                   75,
                   100
               )
           );
        }
        return $object;
    }

    ( On that example, the table ID is 1,  but you can set your table’s ID)

    Alternatively, if you wish to select multiple specific tables that should have this, you can add multiple table ID’s, for example :

    add_filter( 'wpdatatables_filter_table_description', 'verse_show_entries', 10, 3 );
    function verse_show_entries( $object, $table_id, $wpDataTableOBJ ){
        if (in_array($table_id,[1,2,3,4,5,6]){
           $object->dataTableParams->aLengthMenu = array(
               array(
                   10,
                   25,
                   50,
                   75,
                   100
               ),
               array(
                   10,
                   25,
                   50,
                   75,
                   100
               )
           );
        }
        return $object;
    }

    Important to note :

    This hook is not going to change the options in the back-end table settings/Display settings, here the options will look the same :

    2730158179.png

    But it will directly override the settings on the table itself,  ( in both back and front-end),

    so if we check on the table’s available options for number of rows,  it will then activate the hook’s settings in the “Show Number of Entries” dropdown :

    9611596294.png

    Of course, that was an example where we removed the “ALL” rows option,

    but you can modify the hook, to change/add options you need.

    Now, this other workaround is if you wish to change the available row options on the back-end of the table settings.

    You also can’t use this option out-of-the-box, but there’s a way to do it.

    You need to open this file:

     ../wp-content/plugins/wpdatatables/templates/admin/table-settings/table_settings_block.inc.php 

    and around line 367 you’ll see this:

    <select class="form-control selectpicker" id="wdt-rows-per-page"> 
      <option value="1">1</option>   <option value="5">5</option> 
      <option value="10">10</option>   <option value="25">25</option> 
      <option value="50">50</option>   <option value="100">100</option>  
     <option value="-1"><?php _e('All', 'wpdatatables'); ?></option>
    </select>

    * When searching the code, it is best to search for a phrase using CTR+F,  since our devs might add new lines of code during Updates, then the exact line number changes,

    so i advise to search for “Rows per page selection” , and you will find the comment right above this code : 

    Then you can change the options as you need them,

     for this example, i reorder some values, i added option “15”, and changed “All” to “1000”.

      <option value="1">1</option>    
                                         <option value="5">5</option>   
                                            <option value="10">10</option> 
                                            <option value="15">15</option> 
                                             <option value="25">25</option>  
                                         <option value="50">50</option>    
                                             <option value="100">100</option> 
                                          <option value="1000">1000</option>
    6314974469.png

            Then you will see the options look like that, in the plugin, on table’s Display tab :

    9398908774.png

    Then, open ../wp-content/plugins/wpdatatables/source/class.wpdatatable.php 

    and around line 3737 ( or search for “aLengthMenu”), and replace the values as needed, in my example like this:

    $obj->dataTableParams->aLengthMenu = json_decode('[[1,5,10,15,25,50,100,1000],[1,5,10,15,25,50,100,1000]]');

    And the last thing to do is to go to line 544 of the same file ( or search for “setDisplayLength”, and modify it so it looks like this:

    public function setDisplayLength($length) {   
         if (!in_array($length, array(1, 5, 10, 12, 15, 25, 30, 50, 100, 1000))) {  
              return false;

    So, again, change the values as needed.

    Please make sure to delete cache in your browser after you apply the changes.

     It works on my Test table, and Test site;   let me know if it works for you.

    7110967922.png

    Important to note : During updates, this code will be overwritten, it will change to default code, so if you update the plugin, you have to repeat this process.

    We will work on adding a better solution as soon as possible, for the time being, it is like that.

    If you wish to affect the speed of development for these options,

    Please feel free to search on our suggestions page

     to see if someone may be already suggested this feature. If you can’t see it, feel free to add your suggestion there,  and as more people vote, the feature will move higher on the priority list.

    You can certainly follow our changeLog page if you’d like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;

    and our newsletter, so you’re informed about new features, bug fixes, freebies, etc.

    Let me know if that works for you, or if you meant to ask something else, please elaborate.

    Thank you

Viewing 1 replies (of 1 total)
  • The topic ‘limitation possible?’ is closed to new replies.