Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
currency formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
PGimenez committed Aug 13, 2024
1 parent c583dcb commit 256d879
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions assets/js/stippletables.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Vue.component("st-table", {
<div>
<q-table
row-key="__id"
:columns="columns"
:columns="formattedColumns"
v-model="data"
:title="title"
:data="filteredData"
Expand Down Expand Up @@ -158,6 +158,10 @@ Vue.component("st-table", {
},
aggregatetargetoptions: {
type: Array
},
currencycolumns: {
type: Array,
default: () => ['']
}
},
inheritAttrs: false,
Expand All @@ -166,7 +170,8 @@ Vue.component("st-table", {
selectedColumns: [],
isFullscreen: false,
selectedGroupSelect: null,
groupbyisBound: false
groupbyisBound: false,
aggregatebyisBound: false
};
},
computed: {
Expand Down Expand Up @@ -198,14 +203,25 @@ Vue.component("st-table", {
return searchColumns.some(colName => {
let value = row[colName];
console.log(`Checking column ${colName}:`, value);

// Skip null or undefined values
if (value == null) return false;

// Convert to string and check if it includes the filter
return String(value).toLowerCase().includes(this.filter.toLowerCase());
});
});
},
formattedColumns() {
return this.columns.map(col => {
if (this.currencycolumns.includes(col.name)) {
return {
...col,
format: this.formatCurrency
};
}
return col;
});
}
},
methods: {
Expand All @@ -215,6 +231,17 @@ Vue.component("st-table", {
toggleFullscreen() {
this.isFullscreen = !this.isFullscreen;
},
formatCurrency(value) {
if (typeof value !== 'number') {
return value;
}
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2,
maximumFractionDigits: 2
}).format(value);
}
},
created() {
// Check if groupby prop is bound
Expand Down

0 comments on commit 256d879

Please sign in to comment.