forked from Michel2/wp-jquery-datatable
Added the choosen page lenght as an option to the dropdown if it's not one of the default options
This commit is contained in:
@@ -230,6 +230,25 @@ function wp_jdt_shortcode($atts)
|
||||
$table_searching = ($atts['searching'] === 'true') ? 'true' : 'false';
|
||||
|
||||
$table_length_menu = array(10, 25, 50, 100, -1);
|
||||
if (!in_array($table_page_length, $table_length_menu)) {
|
||||
// Add the missing page length option to the array
|
||||
$table_length_menu[] = (int)$table_page_length;
|
||||
|
||||
// Temporarily remove -1 ("All") if present to preserve its position at the end
|
||||
$has_all = false;
|
||||
if (($key = array_search(-1, $table_length_menu)) !== false) {
|
||||
unset($table_length_menu[$key]);
|
||||
$has_all = true;
|
||||
}
|
||||
|
||||
// Sort the remaining numeric options in ascending order
|
||||
sort($table_length_menu);
|
||||
|
||||
// Append -1 back to the end of the array
|
||||
if ($has_all) {
|
||||
$table_length_menu[] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// css and js
|
||||
wp_enqueue_style('jdt-style-data-tables');
|
||||
|
||||
Reference in New Issue
Block a user