Skip to content

Commit ccaef67

Browse files
Merge pull request #17 from Linkurious/LKE-6988-localisation-support
Support utf8 characters and custom delimiter
2 parents 32e23a3 + 3b84ba7 commit ccaef67

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Configuration keys supported only by the data-table plugin:
2121
| :-- | :-- | :-- | :-- |
2222
| `entityType` | "edge" \| "node" (**required**) | Whether to display nodes or edges in the table. | `"node"` |
2323
| `itemType` | string (**required**) | Name of the node category or edge type to display in the table. | `"Company"` |
24+
| `delimiter` | string (**optional**) | The delimiter used for csv files downloads. Only one character is allowed. By default "," is used | `";"` |
2425
| `properties` | string\[] (**optional**) | Property names to include in the table. Defaults to all the properties of `itemType`. | `["name", "address", "vat_number"]` |
2526

2627
Configuration example for 1 data-table instance accesible via `/plugins/table`:

backend/routeHandler.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ module.exports = function configureRoutes(options) {
2626
* @param entityType
2727
* @param itemType
2828
* @param properties
29+
* @param delimiter
2930
* @returns {{message: string}|{message: string}|{message: string}|null|{message: string}}
3031
*/
31-
function checkPluginsConfiguration(schemaTypes, entityType, itemType, properties) {
32+
function checkPluginsConfiguration(schemaTypes, entityType, itemType, properties, delimiter) {
3233
if (entityType && entityType !== 'node' && entityType !== 'edge') {
3334
return {message: 'Invalid plugin configuration “entityType” (must be “node” or “edge”)'};
3435
}
@@ -40,6 +41,9 @@ module.exports = function configureRoutes(options) {
4041
if (properties && (!Array.isArray(properties) || properties.length === 0)) {
4142
return {message: 'Invalid plugin configuration “properties” (must be a non-empty array of property names)'};
4243
}
44+
if (delimiter && delimiter.length != 1) {
45+
return {message: 'Invalid plugin configuration “delimiter” (only one character is allowed)'};
46+
}
4347
return null;
4448
}
4549

@@ -48,7 +52,8 @@ module.exports = function configureRoutes(options) {
4852
const entityType = options.configuration.entityType;
4953
const itemType = options.configuration.itemType;
5054
const properties = options.configuration.properties;
51-
const error = checkPluginsConfiguration(schemaTypes, entityType, itemType, properties);
55+
const delimiter = options.configuration.delimiter;
56+
const error = checkPluginsConfiguration(schemaTypes, entityType, itemType, properties, delimiter);
5257
if (error) {
5358
res.status(412);
5459
res.send(JSON.stringify({status: 412, body: {error}}));

public/js/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,11 @@ function showModal() {
525525
function addButtons() {
526526
// EXPORT TO CSV BUTTON
527527
document.getElementById('button-export').addEventListener('click', () => {
528-
table.download('csv', 'data.csv');
528+
delimiterCharacter = ",";
529+
if (pluginConfiguration.delimiter){
530+
delimiterCharacter = pluginConfiguration.delimiter;
531+
}
532+
table.download('csv', 'data.csv', {delimiter:delimiterCharacter, bom:true});
529533
});
530534

531535
// OPEN EDIT COLUMN MODAL

0 commit comments

Comments
 (0)