webismymind / editablegrid

EditableGrid is an open source Javascript library aimed at turning HTML tables into advanced editable components. It focuses on simplicity: only a few lines of code are required to get your first table up and running.
http://www.editablegrid.net
Other
796 stars 271 forks source link

Not able to set decimal point #115

Open mahekshah opened 8 years ago

mahekshah commented 8 years ago

Hello,

I have mentioned decimal point and thousand separator while defining metadata.

metadata.push({ name: "pricePerUnit", label: "Price Per Unit", datatype: "double($,2)", editable: false, decimal_point: '.',thousands_separator: ',',unit_before_number: true}

but it shows ',' as decimal separator and '.' thousand separator. Also unit is also not coming before the text.

Can you please help me out.

Thanks, Mahek Shah

dsl101 commented 8 years ago

Not sure if this is still an issue, but I'm also getting caught by the default comma and thousands separator being a bit 'European' :). Looking at the code around line 702, I think you have to pass all that stuff as a list in the datatype property, not as extra properties of the metadata item - the smallest set which includes those elements looks like this:

// extract precision, unit and number format from type if 5 given
else if (column.datatype.match(/(.*)\((.*),(.*),(.*),(.*),(.*)\)$/)) {
    column.datatype = RegExp.$1;
    column.unit = RegExp.$2;
    column.precision = parseInt(RegExp.$3);
    column.decimal_point = RegExp.$4;
    column.thousands_separator = RegExp.$5;
    column.unit_before_number = RegExp.$6;

    // trim should be done after fetching RegExp matches beacuse it itself uses a RegExp and causes interferences!
    column.unit = column.unit.trim();
    column.decimal_point = column.decimal_point.trim();
    column.thousands_separator = column.thousands_separator.trim();
    column.unit_before_number = column.unit_before_number.trim() == '1';
}

So you would need something like datatype: "double($, 2, dot, comma, 1)" - note that is not very tested I'm afraid, but should get you heading in the right direction...