11801-Datatables add parameter Start disabled (enable on filter)

This commit is contained in:
Pablo Aragon 2023-08-31 14:58:47 +02:00
parent 5c8789af94
commit 9010d079d3
3 changed files with 40 additions and 5 deletions

View File

@ -3913,6 +3913,11 @@ function ui_print_datatable(array $parameters)
$parameters['toggle_collapsed'] = true; $parameters['toggle_collapsed'] = true;
} }
$parameters['startDisabled'] = false;
if (isset($parameters['start_disabled']) && $parameters['start_disabled'] === true) {
$parameters['startDisabled'] = true;
}
if (!is_array($parameters['order'])) { if (!is_array($parameters['order'])) {
$order = 0; $order = 0;
$direction = 'asc'; $direction = 'asc';
@ -4113,7 +4118,7 @@ function ui_print_datatable(array $parameters)
// Base table. // Base table.
$table = '<table id="'.$table_id.'" '; $table = '<table id="'.$table_id.'" ';
$table .= 'class="'.$parameters['class'].'"'; $table .= 'class="invisible '.$parameters['class'].'"';
$table .= 'style="box-sizing: border-box;'.$parameters['style'].'">'; $table .= 'style="box-sizing: border-box;'.$parameters['style'].'">';
$table .= '<thead><tr class="datatables_thead_tr">'; $table .= '<thead><tr class="datatables_thead_tr">';
@ -4187,13 +4192,19 @@ function ui_print_datatable(array $parameters)
$info_msg_arr['message'] = $emptyTable; $info_msg_arr['message'] = $emptyTable;
$info_msg_arr['div_class'] = 'info_box_container invisible_important datatable-msg-info-'.$table_id; $info_msg_arr['div_class'] = 'info_box_container invisible_important datatable-msg-info-'.$table_id;
$spinner = '<div id="'.$table_id.'-spinner" class="spinner-fixed"><span></span><span></span><span></span><span></span></div>'; $info_msg_arr_filter = [];
$info_msg_arr_filter['message'] = __('Please apply a filter to display the data.');
$info_msg_arr_filter['div_class'] = 'info_box_container invisible_important datatable-msg-info-filter-'.$table_id;
$spinner = '<div id="'.$table_id.'-spinner" class="invisible spinner-fixed"><span></span><span></span><span></span><span></span></div>';
// TODO This widget should take a return: ui_print_info_message($info_msg_arr, '', true) // TODO This widget should take a return: ui_print_info_message($info_msg_arr, '', true)
$info_msg = '<div>'.ui_print_info_message($info_msg_arr).'</div>'; $info_msg = '<div>'.ui_print_info_message($info_msg_arr).'</div>';
$info_msg_filter = '<div>'.ui_print_info_message($info_msg_arr_filter, true).'</div>';
$err_msg = '<div id="error-'.$table_id.'"></div>'; $err_msg = '<div id="error-'.$table_id.'"></div>';
$output = $info_msg.$err_msg.$filter.$extra.$spinner.$table.$js; $output = $info_msg.$info_msg_filter.$err_msg.$filter.$extra.$spinner.$table.$js;
if (is_ajax() === false) { if (is_ajax() === false) {
ui_require_css_file('datatables.min', 'include/styles/js/'); ui_require_css_file('datatables.min', 'include/styles/js/');
ui_require_css_file('tables'); ui_require_css_file('tables');

View File

@ -126,6 +126,11 @@ if (typeof dt.ajax_data !== "undefined") {
ajaxData = dt.ajax_data; ajaxData = dt.ajax_data;
} }
var startDisabled = false;
if (dt.startDisabled === true) {
startDisabled = true;
}
$(document).ready(function() { $(document).ready(function() {
function checkPages() { function checkPages() {
if (dt_table.page.info().pages > 1) { if (dt_table.page.info().pages > 1) {
@ -335,7 +340,25 @@ $(document).ready(function() {
} }
$.extend(settings_datatable, ajaxOrData); $.extend(settings_datatable, ajaxOrData);
var dt_table = $(`#${dt.table_id}`).DataTable(settings_datatable);
var dt_table;
if (startDisabled === true) {
$(`.datatable-msg-info-filter-${dt.id}`)
.removeClass("invisible_important")
.show();
$(`div#${dt.id}-spinner`).hide();
$(`#${dt.table_id}`).hide();
$(`#button-form_${dt.table_id}_search_bt`).click(function() {
$(`.datatable-msg-info-filter-${dt.id}`).hide();
$(`#${dt.table_id}`).show();
dt_table = $(`#${dt.table_id}`).DataTable(settings_datatable);
});
} else {
dt_table = $(`#${dt.table_id}`).DataTable(settings_datatable);
}
$(`#button-${dt.form_id}_search_bt`).click(function() { $(`#button-${dt.form_id}_search_bt`).click(function() {
dt_table.draw().page(0); dt_table.draw().page(0);

View File

@ -407,7 +407,7 @@ if ($agent_view_page === true) {
[ [
'id' => 'alerts_status_datatable', 'id' => 'alerts_status_datatable',
'class' => 'info_table', 'class' => 'info_table',
'style' => 'width: 99%;', 'style' => 'width: 100%;',
'columns' => $columns, 'columns' => $columns,
'column_names' => $column_names, 'column_names' => $column_names,
'no_sortable_columns' => $no_sortable_columns, 'no_sortable_columns' => $no_sortable_columns,
@ -439,6 +439,7 @@ if ($agent_view_page === true) {
$strict_user $strict_user
), ),
], ],
'start_disabled' => true,
] ]
); );
} }