diff --git a/docs/en_US/images/preferences_sql_results_grid.png b/docs/en_US/images/preferences_sql_results_grid.png index 402c2e58d..a9a2f7e80 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 c7d87b85b..6d2a3b58c 100644 --- a/docs/en_US/preferences.rst +++ b/docs/en_US/preferences.rst @@ -372,6 +372,9 @@ 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. +* When the *Column data auto-resize?* switch is set to *True*, then data + output columns will auto fit to max data width. If it is set to *False* then + size is set based on data type or column name. * Use the *Result copy field separator* drop-down listbox to select the field separator for copied data. * Use the *Result copy quote character* drop-down listbox to select the quote diff --git a/docs/en_US/release_notes_5_3.rst b/docs/en_US/release_notes_5_3.rst index c6f576ae8..41f6220dc 100644 --- a/docs/en_US/release_notes_5_3.rst +++ b/docs/en_US/release_notes_5_3.rst @@ -9,6 +9,7 @@ This release contains a number of bug fixes and new features since the release o New features ************ +| `Issue #5954 `_ - Added support to set auto width of columns by content size in the data output window. | `Issue #6158 `_ - Added support to connect PostgreSQL servers via Kerberos authentication. | `Issue #6397 `_ - Added "IF NOT EXISTS" clause while creating tables and partition tables which is convenient while using the ERD tool. diff --git a/web/pgadmin/static/js/slickgrid/plugins/slick.autocolumnsize.js b/web/pgadmin/static/js/slickgrid/plugins/slick.autocolumnsize.js index 85b339139..1e2c29036 100644 --- a/web/pgadmin/static/js/slickgrid/plugins/slick.autocolumnsize.js +++ b/web/pgadmin/static/js/slickgrid/plugins/slick.autocolumnsize.js @@ -10,7 +10,7 @@ }, }); - function AutoColumnSize(maxWidth) { + function AutoColumnSize() { var grid, $container, context, keyCodes = { @@ -19,13 +19,14 @@ function init(_grid) { grid = _grid; - maxWidth = maxWidth || 200; $container = $(grid.getContainerNode()); $container.on('dblclick.autosize', '.slick-resizable-handle', reSizeColumn); $container.keydown(handleControlKeys); context = document.createElement('canvas').getContext('2d'); + // Expose resizeAllColumns method to call from outside of this file. + grid.resizeAllColumns = resizeAllColumns; } function destroy() { @@ -43,12 +44,16 @@ var allColumns = grid.getColumns(); elHeaders.each(function(index, el) { var columnDef = $(el).data('column'); + // Check if width is set then no need to resize that column. + if (typeof(columnDef.width) !== 'undefined' && !isNaN(columnDef.width)) { + return; + } + var headerWidth = getElementWidth(el); var colIndex = grid.getColumnIndex(columnDef.id); var column = allColumns[colIndex]; var autoSizeWidth = Math.max(headerWidth, getMaxColumnTextWidth(columnDef, colIndex)) + 1; - autoSizeWidth = Math.min(maxWidth, autoSizeWidth); - column.width = autoSizeWidth; + column.width = autoSizeWidth + (columnDef.addWidth || 0); }); grid.setColumns(allColumns); grid.onColumnsResized.notify(); diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index 7f93c5e83..f6fe7f985 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -871,6 +871,13 @@ define('tools.querytool', [ self.handler['table_name'] = table_name; column_size[table_name] = column_size[table_name] || {}; + // Keep track of column_data_auto_resize preferences value + if (_.isUndefined(self.auto_resize_column_based_on_data) || self.auto_resize_column_based_on_data !== self.preferences.column_data_auto_resize) { + self.auto_resize_column_based_on_data = self.preferences.column_data_auto_resize; + column_size[table_name] = {}; + } + + _.each(columns, function(c) { c.display_name = _.escape(c.display_name); c.column_type = _.escape(c.column_type); @@ -898,13 +905,34 @@ define('tools.querytool', [ // column name. var column_type = c.column_type.trim(); var label = c.name.length > column_type.length ? _.escape(c.display_name) : column_type; + var iconWidth = 0; + // increase width to add 'view' button + if (c.cell == 'geometry' || c.cell == 'geography') { + iconWidth += 28; + } + // Increase width for editable/read-only icon + if(!_.isUndefined(c.can_edit)) { + iconWidth += 12; + } if (_.isUndefined(column_size[table_name][options.nonative_field])) { - options['width'] = SqlEditorUtils.calculateColumnWidth(label); - column_size[table_name][c.nonative_field] = options['width']; + /* If column_data_auto_resize is true then for the first time set + * the addWidth parameter to iconWidth and if it is false then + * calculate width based on longer string among data type or + * column name. + */ + if (self.preferences.column_data_auto_resize) { + options['addWidth'] = iconWidth; + options['width'] = NaN; + } else { + options['width'] = SqlEditorUtils.calculateColumnWidth(label); + options['width'] += iconWidth; + column_size[table_name][c.nonative_field] = options['width']; + } } else { options['width'] = column_size[table_name][options.nonative_field]; } + // If grid is editable then add editor else make it readonly if (c.cell == 'oid' && c.name == 'oid') { options['editor'] = null; @@ -927,7 +955,6 @@ define('tools.querytool', [ options['formatter'] = Slick.Formatters.Binary; } else if (c.cell == 'geometry' || c.cell == 'geography') { // increase width to add 'view' button - options['width'] += 28; options['can_edit'] = false; } else { options['editor'] = c.can_edit ? Slick.Editors.pgText : @@ -936,9 +963,6 @@ define('tools.querytool', [ } if(!_.isUndefined(c.can_edit)) { - // Increase width for editable/read-only icon - options['width'] += 12; - let tooltip = ''; if(c.can_edit) tooltip = gettext('Editable column'); @@ -1148,6 +1172,10 @@ define('tools.querytool', [ dataView.onRowsChanged.subscribe(function(e, args) { grid.invalidateRows(args.rows); grid.render(); + // Resize all columns if column_data_auto_resize is true. + if (self.preferences.column_data_auto_resize) { + grid.resizeAllColumns && grid.resizeAllColumns(); + } }); // Listener function which will be called before user updates existing cell diff --git a/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py b/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py index 543523c98..92723c43a 100644 --- a/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py +++ b/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py @@ -268,6 +268,16 @@ def register_query_tool_preferences(self): } ) + self.column_data_auto_resize = self.preference.register( + 'Results_grid', 'column_data_auto_resize', + gettext("Column data auto-resize?"), 'boolean', True, + category_label=PREF_LABEL_RESULTS_GRID, + help_str=gettext( + 'If set to True then data output columns will auto fit to max ' + 'data width else it is fit, based on data type or column name.' + ) + ) + self.sql_font_size = self.preference.register( 'Editor', 'sql_font_size', gettext("Font size"), 'numeric', '1',