Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing option properties for Column #133

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ MISC.:
* Function sort() is called by renderGrid only if there is a currently defined sorting order (to avoid a double render) but the expected callback tableSorted is still called
* Added column attributes: decimal_point, thousands_separator, unit_before_number.
All have a default value and can be overridden in the XML column type declaration, as follows:
datatype(unit, precision, decimal_point, thousands_separator, unit_before_number[, nanSymbol])
datatype(unit, precision, decimal_point, thousands_separator, unit_before_number[, nansymbol])
e.g. double(€, 2, comma, dot, 0, n/a)
* Lots of other bugfixes and minor improvements!

Expand Down
24 changes: 11 additions & 13 deletions editablegrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function Column(config)
unit: null,
precision: -1, // means that all decimals are displayed
nansymbol: '',
decimal_point: ',',
thousands_separator: '.',
decimal_point: ',', // can also be specified by comma or dot
thousands_separator: '.', // can also be specified by comma or dot
unit_before_number: false,
bar: true, // is the column to be displayed in a bar chart ? relevant only for numerical columns
hidden: false, // should the column be hidden by default
Expand All @@ -37,7 +37,7 @@ function Column(config)
};

// override default properties with the ones given
for (var p in props) this[p] = (typeof config == 'undefined' || typeof config[p] == 'undefined') ? props[p] : config[p];
for (var p in props) this[p] = (typeof config == 'undefined' || typeof config[p] == 'undefined' || config[p] == null) ? props[p] : config[p];
}

Column.prototype.getOptionValuesForRender = function(rowIndex) {
Expand Down Expand Up @@ -602,10 +602,16 @@ EditableGrid.prototype.processJSON = function(jsonData)
this.columns.push(new Column({
name: columndata.name,
label: (columndata.label ? columndata.label : columndata.name),
datatype: (columndata.datatype ? columndata.datatype : "string"),
editable: (columndata.editable ? true : false),
bar: (typeof columndata.bar == 'undefined' ? true : (columndata.bar || false)),
renderable: columndata.renderable,
datatype: (columndata.datatype ? columndata.datatype : "string"),
decimal_point: columndata.decimal_point,
unit: columndata.unit,
unit_before_number: columndata.unit_before_number,
thousands_separator: columndata.thousands_separator,
bar: (typeof columndata.bar == 'undefined' ? true : (columndata.bar || false)),
hidden: (typeof columndata.hidden == 'undefined' ? false : (columndata.hidden ? true : false)),
nansymbol: columndata.nansymbol,
optionValuesForRender: optionValuesForRender,
optionValues: optionValues
}));
Expand Down Expand Up @@ -697,14 +703,6 @@ EditableGrid.prototype.processColumns = function()

EditableGrid.prototype.parseColumnType = function(column)
{
// reset
column.unit = null;
column.precision = -1;
column.decimal_point = ',';
column.thousands_separator = '.';
column.unit_before_number = false;
column.nansymbol = '';

// extract precision, unit and number format from type if 6 given
if (column.datatype.match(/(.*)\((.*),(.*),(.*),(.*),(.*),(.*)\)$/)) {
column.datatype = RegExp.$1;
Expand Down