Use more sensible column sizes for the data output in the query tool. Fixes #1789

Per Akshay:

I have tried to get the width of the content but we are sending complete data as collection to the SlickGrid. We will have to fetch the content of each column and figure out the maximum length for that column by iterating all the rows is too expensive. Apart from that to set the width in 'ch' we will have to do it using css. With current implementation we are setting the column option of the SlickGrid from javascript code.

I have fixed this issue by setting the width of the columns based on data type. I have set the width of boolean column to 60, all the numeric/integer columns to 80 and for all other data types it is 20% of the container width as 33% is too wide.
pull/3/head
Akshay Joshi 2016-12-12 10:13:53 +00:00 committed by Dave Page
parent 53481023fa
commit 686237413c
1 changed files with 51 additions and 0 deletions

View File

@ -477,6 +477,53 @@ define(
return false;
},
get_column_width: function (column_type, grid_width) {
switch(column_type) {
case "bigint":
case "bigint[]":
case "bigserial":
case "bit":
case "bit[]":
case "bit varying":
case "bit varying[]":
case "\"char\"":
case "decimal":
case "decimal[]":
case "double precision":
case "double precision[]":
case "int4range":
case "int4range[]":
case "int8range":
case "int8range[]":
case "integer":
case "integer[]":
case "money":
case "money[]":
case "numeric":
case "numeric[]":
case "numrange":
case "numrange[]":
case "oid":
case "oid[]":
case "real":
case "real[]":
case "serial":
case "smallint":
case "smallint[]":
case "smallserial":
return 80;
case "boolean":
case "boolean[]":
return 60;
}
/* In case of other data types we will calculate
* 20% of the total container width and return it.
*/
return Math.round((grid_width * 20)/ 100)
},
/* Regarding SlickGrid usage in render_grid function.
SlickGrid Plugins:
@ -570,6 +617,7 @@ define(
grid_columns.push(checkboxSelector.getColumnDefinition());
var grid_width = $($('#editor-panel').find('.wcFrame')[1]).width()
_.each(columns, function(c) {
var options = {
id: c.name,
@ -577,6 +625,9 @@ define(
name: c.label
};
// Get the columns width based on data type
options['width'] = self.get_column_width(c.type, grid_width);
// If grid is editable then add editor else make it readonly
if(c.cell == 'Json') {
options['editor'] = is_editable ? Slick.Editors.JsonText