Skip to content
Snippets Groups Projects
Commit b255e54a authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update Table.js to reset it properly.

parent ccd505b9
No related branches found
No related tags found
2 merge requests!30Release 0.9.3,!2928 grid filter with dict list
......@@ -2,11 +2,11 @@
* Form field to render database field with the type JSON as a table.
* The size of the table is numRows x numColumns. It is fixed.
*
* The widget renders a JSON object which if is a list (nRow) of list(nCol).
* The widget renders a JSON object which if is an array(nRow) of array(nCol).
* Possible values are boolean, date, float and string objects.
*
* The interface is less rich than the one of the Ext.form.field.Base since
* it only contains the basic methods getErrors, getValue and setValue.
* it only contains the basic methods getValue and setValue.
*
* @since 0.9.3
*
......@@ -75,11 +75,9 @@ Ext.define('Dbui.form.field.Table', {
initComponent: function () {
var me = this,
data = [],
header = me.header || [],
numColumns = me.numColumns,
numRows = me.numRows,
cfgColumns, grid, i, name, row;
cfgColumns, grid, i, name;
// field"s name for the store, data index for the column
// as well as column labels: (A, B, C , ....) or user defined
......@@ -89,16 +87,10 @@ Ext.define('Dbui.form.field.Table', {
}
}
// dummy data for the local store
for (i = 0; i < numRows; i += 1) {
row = new Array(numColumns);
data.push(row);
}
// instantiate the store
me.store = Ext.create('Ext.data.ArrayStore', {
fields: header,
data: data
data: me.initData()
});
// first column of the grid contains the row number
......@@ -124,6 +116,7 @@ Ext.define('Dbui.form.field.Table', {
// when a cell is edited it is not marked dirty
me.items = [{
columns: cfgColumns,
columnLines: true,
hideHeaders: me.hideHeader,
plugins: {
ptype: 'cellediting',
......@@ -209,6 +202,26 @@ Ext.define('Dbui.form.field.Table', {
return data;
},
/**
* Generate the data block corresponding to an empty table
* @return {Array[]} data
*/
initData: function () {
"use strict";
var me = this,
data = [],
numColumns = me.numColumns,
i, row;
for (i = 0; i < me.numRows; i += 1) {
row = new Array(numColumns);
data.push(row);
}
return data;
},
/**
* Block the context menu.
*
......@@ -241,6 +254,28 @@ Ext.define('Dbui.form.field.Table', {
me.fireEvent('change', me);
},
/**
* Reset the field to the originalValue.
* Supersede the mixin method to initialize the table with empty data.
*
*/
reset: function () {
"use strict";
var me = this,
oriVal = me.originalValue;
console.log("reset", oriVal);
// check that original value is defined
if (!(Ext.isArray(oriVal) && oriVal.length === me.numColumns)) {
me.originalValue = me.initData();
}
// rest of the processing by the mixing Field
me.mixins.field.reset.call(me, arguments);
},
/**
* Set the value for the table.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment