Commit 04765b07 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update the view/grid to fix some crash appearing when an hidden column is activated.

parent ee0d5707
......@@ -125,4 +125,4 @@ def grid():
title = do_title(config, selector)
# delegate the grid rendering to the view
return dict(cfg_store=json.dumps(store), grid=grid, title=title)
return dict(cfg_store=store, grid=grid, title=title)
......@@ -688,9 +688,9 @@ class List(BaseReport):
"""Build the configuration for the ``Dbui.grid.Panel``.
Returns:
plugin_dbui.Grid:
the configuration of the ``Dbui.grid.Panel``.
The properties columns and features are JSON encoded.
gluon.storage.Storage:
the keys are ``columns`` and ``features`` and the
corresponding values are list of dictionary.
"""
config = self.config
......@@ -707,14 +707,7 @@ class List(BaseReport):
grid.columns.append(cfg)
# features from the configuration
grid.features = config.features
# JSON encoding
# reference to javascript function or the function itself
# are surrounded by double quoted. removed them.
grid.columns = json.dumps(grid.columns)
grid.columns = \
re.sub('("renderer": *)(")(\w+)(")', r'\1\3', grid.columns)
grid.features = json.loads(config.features)
return grid
......
......@@ -2,7 +2,7 @@
#--------------------------------------------------------------------------
#
# The python controller return the variables:
# - cfg_store (string)
# - cfg_store (Storage)
# - grid (Storage)
# - title (string)
#
......@@ -22,26 +22,60 @@
response.write(H2(title, _class="dbui-h2 dbui-small-cap"))
response.write(DIV(_id=divgrid))
#
# Convert store and grid configuration as string
#
cfg_grid = json.dumps(grid)
cfg_store = json.dumps(cfg_store)
}}
<script>
<script type="text/javascript">
var cfgStore = {{=XML(cfg_store)}},
columns = {{=XML(grid.columns)}},
var cfgGrid = {{=XML(cfg_grid)}},
cfgStore = {{=XML(cfg_store)}},
columns = cfgGrid.columns,
divgrid = '{{=divgrid}}',
features ={{=XML(grid.features)}},
grid;
nColumns = columns.length,
i, grid;
// backward compatibility
// Ext JS 4.2.1 the width of the column is defined using the property flex
// Ext JS 6.0.1 this cause crash of the grid when a hidden column is activated
// The workaround is to destroy the flex property and to use the
// columnWidth instead. the latter is a percentage ranging from 0 to 1.
for (i = 0; i < nColumns; i += 1) {
column = columns[i];
if (column.flex !== undefined && column.columnWidth === undefined) {
if (column.flex <= 1) {
column.columnWidth = column.flex * 0.1;
} else {
column.columnWidth = 1;
}
}
delete column.flex;
}
// convert renderer property
// typicaly a string to a function
for (i = 0; i < nColumns; i += 1) {
column = columns[i];
if (column.renderer !== undefined) {
column.renderer = eval(column.renderer);
}
}
//
// instantiate the grid
//
grid = Ext.create('Dbui.grid.Panel', {
cfgGrid = Ext.apply(cfgGrid, {
plugins: ['pGridExport', 'pMathJax'],
store: cfgStore,
columns: columns,
features: features,
forceFit: true,
padding: "10 40 20 30",
renderTo: divgrid
});
Ext.create('Dbui.grid.Panel', cfgGrid);
</script>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment