Added option to provide maximum width of the column when 'Resize by data?’ option in the preferences is set to True. Fixes #6559

This commit is contained in:
Akshay Joshi
2021-06-28 11:51:21 +05:30
parent e095d382b3
commit e68c8305a2
6 changed files with 25 additions and 3 deletions

View File

@@ -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);

View File

@@ -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);
}
});

View File

@@ -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',