Okay
  Public Ticket #3228974
Removing "All" from dropdown in tables
Closed

Comments

  • Syed Omar started the conversation

    Hello,

    I would like the users to be able to select the number of rows they can display on the page. But I don't want to give them the option of "All". Just 10, 25, 50, and the maximum is 100.

    How can this be done?

    Thank you

  •  1,708
    Miloš replied


                 

    Hey, Syed .smile.png

    Sorry for the delay, we had a weekend break.

    -

    We don't have a built-in solution for this yet, but there is a workaround

    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.

    You may also want to add the value in

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

     around line 570, 

    if you wish to add that value to possible column options (if you have a select-box filter, or selectbox editor input type, this would be the number of values displayed in those drop-downs).

    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 yousmile.png

    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.

    Thank you   smile.png              


    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Syed Omar replied

    Thank you! This is very helpful

  •  1,708
    Miloš replied

    Hi, Syed 

    Apology for this late reply, we had our National Holiday.

    You're very welcome.smile.png I am happy to help.

    As you know, please don't hesitate to reach out to us with new tickets whenever you have any questions.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables