2

On my site I am using the plugin wpDataTables (based on jQuery DataTables). For example, when I type HB into the search field, I get 10 results (prices) but I only need 6.

So I want to change the iDisplayLength from 10 to 6 but it's not working as suggested @ datatables.net

Here are some Front-end callbacks via JS. Would it be possible via these front-end callbacks?

Gyrocode.com
  • 57,606
  • 14
  • 150
  • 185

1 Answers1

1

Watch the video on Using filters and actions where author of wpdatatables explains how to do almost exactly what you want.

Basically you need to add the following code to functions.php of your WordPress theme.

Please note that this code will affect all tables on your site. If you want to target a specific table then you need to change iDisplayLength param only when $table_id equals to your table ID.

function mytheme_wpdatatables_filter_table_description($object, $table_id){
   $object->dataTableParams->iDisplayLength = 6;

   return $object;
}
add_filter('wpdatatables_filter_table_description', 'mytheme_wpdatatables_filter_table_description', 10, 2);
Gyrocode.com
  • 57,606
  • 14
  • 150
  • 185
  • Fantastic! Thanks so much. – user3350511 Jul 24 '15 at 08:58
  • Here is another issue: As an example, the values D and DH have different prices. In the search field, when I type in D I get a wrong result (=wrong price). I understand the „logic“ behind it. Because D is included in DH. Is there any way to say: If I type in D then result = price for D (and not DH)? Thanks. – user3350511 Jul 24 '15 at 09:28
  • @user3350511, that may be possible with JavaScript. I would suggest starting a new question since this will require a different approach/solution. – Gyrocode.com Jul 24 '15 at 12:11
  • Thanks for your suggestion. You are right. New question is here: http://stackoverflow.com/questions/31611525/wrong-results-in-datatable – user3350511 Jul 24 '15 at 14:02