mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 00:56:02 +00:00
Merge pull request #1286 from dbgate/feature/custom-thousands-separator
Feature/custom thousands separator
This commit is contained in:
@@ -200,6 +200,12 @@ function stringifyJsonToGrid(value): ReturnType<typeof stringifyCellValue> {
|
|||||||
return { value: '(JSON)', gridStyle: 'nullCellStyle' };
|
return { value: '(JSON)', gridStyle: 'nullCellStyle' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatNumberCustomSeparator(value, thousandsSeparator) {
|
||||||
|
const [intPart, decPart] = value.split('.');
|
||||||
|
const intPartWithSeparator = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, thousandsSeparator);
|
||||||
|
return decPart ? `${intPartWithSeparator}.${decPart}` : intPartWithSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
export function stringifyCellValue(
|
export function stringifyCellValue(
|
||||||
value,
|
value,
|
||||||
intent:
|
intent:
|
||||||
@@ -210,7 +216,7 @@ export function stringifyCellValue(
|
|||||||
| 'exportIntent'
|
| 'exportIntent'
|
||||||
| 'clipboardIntent',
|
| 'clipboardIntent',
|
||||||
editorTypes?: DataEditorTypesBehaviour,
|
editorTypes?: DataEditorTypesBehaviour,
|
||||||
gridFormattingOptions?: { useThousandsSeparator?: boolean },
|
gridFormattingOptions?: { thousandsSeparator?: string},
|
||||||
jsonParsedValue?: any
|
jsonParsedValue?: any
|
||||||
): {
|
): {
|
||||||
value: string;
|
value: string;
|
||||||
@@ -351,13 +357,15 @@ export function stringifyCellValue(
|
|||||||
if (_isNumber(value)) {
|
if (_isNumber(value)) {
|
||||||
switch (intent) {
|
switch (intent) {
|
||||||
case 'gridCellIntent':
|
case 'gridCellIntent':
|
||||||
return {
|
const separator = gridFormattingOptions?.thousandsSeparator;
|
||||||
value:
|
let formattedValue;
|
||||||
gridFormattingOptions?.useThousandsSeparator && (value >= 10000 || value <= -10000)
|
if (separator === 'none' || (value < 1000 && value > -1000)) formattedValue = value.toString();
|
||||||
? value.toLocaleString()
|
else if (separator === 'system') formattedValue = value.toLocaleString();
|
||||||
: value.toString(),
|
else if (separator === 'space') formattedValue = formatNumberCustomSeparator(value.toString(), ' ');
|
||||||
gridStyle: 'valueCellStyle',
|
else if (separator === 'nobreakspace') formattedValue = formatNumberCustomSeparator(value.toString(), '\u202F');
|
||||||
};
|
else if (separator === 'comma') formattedValue = formatNumberCustomSeparator(value.toString(), ',');
|
||||||
|
else if (separator === 'dot') formattedValue = formatNumberCustomSeparator(value.toString(), '.');
|
||||||
|
return { value: formattedValue, gridStyle: 'valueCellStyle' };
|
||||||
default:
|
default:
|
||||||
return { value: value.toString() };
|
return { value: value.toString() };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { getBoolSettingsValue } from '../settings/settingsTools';
|
import { getStringSettingsValue } from '../settings/settingsTools';
|
||||||
import { stringifyCellValue } from 'dbgate-tools';
|
import { stringifyCellValue } from 'dbgate-tools';
|
||||||
|
|
||||||
export let rowData;
|
export let rowData;
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
value,
|
value,
|
||||||
'gridCellIntent',
|
'gridCellIntent',
|
||||||
editorTypes,
|
editorTypes,
|
||||||
{ useThousandsSeparator: getBoolSettingsValue('dataGrid.thousandsSeparator', false) },
|
{ thousandsSeparator: getStringSettingsValue('dataGrid.thousandsSeparatorChar', 'system') },
|
||||||
jsonParsedValue
|
jsonParsedValue
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,19 @@ defaultValue="100"
|
|||||||
{/if}
|
{/if}
|
||||||
<!-- <FormCheckboxField name="dataGrid.showHintColumns" label="Show foreign key hints" defaultValue={true} /> -->
|
<!-- <FormCheckboxField name="dataGrid.showHintColumns" label="Show foreign key hints" defaultValue={true} /> -->
|
||||||
|
|
||||||
<FormCheckboxField
|
<FormSelectField
|
||||||
name="dataGrid.thousandsSeparator"
|
label={_t('settings.dataGrid.thousandsSeparator', { defaultMessage: 'Thousands separator for numbers' })}
|
||||||
label={_t('settings.dataGrid.thousandsSeparator', {
|
name="dataGrid.thousandsSeparatorChar"
|
||||||
defaultMessage: 'Use thousands separator for numbers',
|
isNative
|
||||||
})}
|
defaultValue='none'
|
||||||
|
options={[
|
||||||
|
{ value: 'none', label: _t('settings.dataGrid.thousandsSeparator.none', { defaultMessage: 'None' }) },
|
||||||
|
{ value: 'system', label: _t('settings.dataGrid.thousandsSeparator.system', { defaultMessage: 'System' }) },
|
||||||
|
{ value: 'space', label: _t('settings.dataGrid.thousandsSeparator.space', { defaultMessage: 'Space' }) },
|
||||||
|
{ value: 'nobreakspace', label: _t('settings.dataGrid.thousandsSeparator.narrowNoBreakSpace', { defaultMessage: 'Narrow no-break space' }) },
|
||||||
|
{ value: 'comma', label: _t('settings.dataGrid.thousandsSeparator.comma', { defaultMessage: 'Comma (,)' }) },
|
||||||
|
{ value: 'dot', label: _t('settings.dataGrid.thousandsSeparator.dot', { defaultMessage: 'Dot (.)' }) },
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormTextField
|
<FormTextField
|
||||||
|
|||||||
Reference in New Issue
Block a user