diff --git a/docs/en_US/images/preferences_sql_results_grid.png b/docs/en_US/images/preferences_sql_results_grid.png index f72e2c4bb..235b61924 100644 Binary files a/docs/en_US/images/preferences_sql_results_grid.png and b/docs/en_US/images/preferences_sql_results_grid.png differ diff --git a/docs/en_US/preferences.rst b/docs/en_US/preferences.rst index bfcfb79f7..1e82c6c44 100644 --- a/docs/en_US/preferences.rst +++ b/docs/en_US/preferences.rst @@ -374,6 +374,10 @@ Use the fields on the *Options* panel to manage editor preferences. Use the fields on the *Results grid* panel to specify your formatting preferences for copied data. +* Specify the maximum width of the column when 'Resize by data?' is set to True. + If it is set to 0 then columns will auto-size to the maximum width of the data + in the column. If 'Resize by data?' is set to False then this setting won't + take any effect. * When the *Resize by data?* switch is set to *True*, then data columns will auto-size to the maximum width of the data in the column as loaded in the first batch. If False, the column will be sized to the widest of the data diff --git a/docs/en_US/release_notes_5_5.rst b/docs/en_US/release_notes_5_5.rst index 6636a0539..04a2622a1 100644 --- a/docs/en_US/release_notes_5_5.rst +++ b/docs/en_US/release_notes_5_5.rst @@ -10,6 +10,7 @@ New features ************ | `Issue #3920 `_ - Do not block the query editor window when running a query. +| `Issue #6559 `_ - Added option to provide maximum width of the column when 'Resize by data?’ option in the preferences is set to True. Housekeeping ************ diff --git a/web/pgadmin/static/js/slickgrid/plugins/slick.autocolumnsize.js b/web/pgadmin/static/js/slickgrid/plugins/slick.autocolumnsize.js index 1e2c29036..9aa6eba78 100644 --- a/web/pgadmin/static/js/slickgrid/plugins/slick.autocolumnsize.js +++ b/web/pgadmin/static/js/slickgrid/plugins/slick.autocolumnsize.js @@ -39,7 +39,7 @@ } } - function resizeAllColumns() { + function resizeAllColumns(maxWidth) { var elHeaders = $container.find('.slick-header-column'); var allColumns = grid.getColumns(); elHeaders.each(function(index, el) { @@ -53,6 +53,10 @@ var colIndex = grid.getColumnIndex(columnDef.id); var column = allColumns[colIndex]; var autoSizeWidth = Math.max(headerWidth, getMaxColumnTextWidth(columnDef, colIndex)) + 1; + // If max width is provided and it is greater than 0 + if (typeof(maxWidth) !== 'undefined' && maxWidth > 0) { + autoSizeWidth = Math.min(maxWidth, autoSizeWidth); + } column.width = autoSizeWidth + (columnDef.addWidth || 0); }); grid.setColumns(allColumns); diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index bd25cef76..32222297f 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -1189,7 +1189,7 @@ define('tools.querytool', [ grid.render(); // Resize all columns if column_data_auto_resize is true. if (self.preferences.column_data_auto_resize) { - grid.resizeAllColumns && grid.resizeAllColumns(); + grid.resizeAllColumns && grid.resizeAllColumns(self.preferences.column_data_max_width); } }); diff --git a/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py b/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py index 5d222721f..c80143cb0 100644 --- a/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py +++ b/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py @@ -273,13 +273,26 @@ def register_query_tool_preferences(self): gettext("Resize by data?"), 'boolean', True, category_label=PREF_LABEL_RESULTS_GRID, help_str=gettext( - 'If set to True then data columns will auto-size to the maximum' + 'If set to True then data columns will auto-size to the maximum ' 'width of the data in the column as loaded in the first batch. If ' 'False, the column will be sized to the widest of the data type ' 'or column name.' ) ) + self.column_data_max_width = self.preference.register( + 'Results_grid', 'column_data_max_width', + gettext("Maximum column width"), 'integer', 0, + category_label=PREF_LABEL_RESULTS_GRID, + help_str=gettext( + 'Specify the maximum width of the column when \'Resize by data?\' ' + 'is set to True. If it is set to 0 then columns will auto-size to ' + 'the maximum width of the data in the column. If ' + '\'Resize by data?\' is set to False then this setting won\'t ' + 'take any effect.' + ) + ) + self.sql_font_size = self.preference.register( 'Editor', 'sql_font_size', gettext("Font size"), 'numeric', '1',