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

Extend exportFunction (csv) with the whole record #2209

Closed
leibnizman opened this issue Jul 21, 2021 · 0 comments
Closed

Extend exportFunction (csv) with the whole record #2209

leibnizman opened this issue Jul 21, 2021 · 0 comments
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@leibnizman
Copy link

Hi,

while trying to use the exportCSV function I encountered an issue with the exportFunction. The current implementation of the exportFunction has the field and the cellData as a parameter. To export my table I need to have access to the whole record, because my data is nested in an array (cellData returns null and my exportFunction isn't called). I created a patch for [email protected] to solve this issue.

Here is the diff that solved my problem:

diff --git a/node_modules/primereact/components/datatable/DataTable.js b/node_modules/primereact/components/datatable/DataTable.js
index e1d5b19..16ca131 100644
--- a/node_modules/primereact/components/datatable/DataTable.js
+++ b/node_modules/primereact/components/datatable/DataTable.js
@@ -1079,14 +1079,20 @@ var DataTable = /*#__PURE__*/function (_Component) {
             var cellData = _ObjectUtils.default.resolveFieldData(record, field);
 
             if (cellData != null) {
-              if (_this5.props.exportFunction) {
+                if (_this5.props.exportFunction) {
+                  cellData = _this5.props.exportFunction({
+                    data: cellData,
+                    field: field,
+                    record: record
+                  });
+                } else cellData = String(cellData).replace(/"/g, '""');
+              } else if (_this5.props.exportFunction) {
                 cellData = _this5.props.exportFunction({
-                  data: cellData,
-                  field: field
+                  data:  cellData,
+                  field: field,
+                  record: record
                 });
-              } else cellData = String(cellData).replace(/"/g, '""');
-            } else cellData = '';
-
+              } else cellData = '';  
             csv += '"' + cellData + '"';
 
             if (_i < columns.length - 1) {

This issue body was partially generated by patch-package.

@mertsincan mertsincan self-assigned this Nov 8, 2021
@mertsincan mertsincan added the Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add label Nov 8, 2021
@mertsincan mertsincan added this to the 7.0.0.Final milestone Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

No branches or pull requests

2 participants