Skip to content

Commit aedd908

Browse files
Merge pull request #13 from app-generator/export-issue
fix export issues
2 parents eba49e6 + 681df46 commit aedd908

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

django_dyn_dt/templates/static/src/controller/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ export const exportController = (dataTable) => {
211211
export const exportData = (dataTable, type) => {
212212

213213
const searchParam = new URLSearchParams(window.location.search).get('search') || ''
214-
215-
const hiddenColumns = myData.headings.filter((d,i) => !dataTable.columns.visible(i))
214+
215+
const hiddenColumns = myData.headings.filter((d,i) => !dataTable.columns().visible(i))
216216

217217
fetch (`/datatb/${modelName}/export/`,
218218
{method: 'POST',body: JSON.stringify({

django_dyn_dt/views.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,9 @@ def export(request, **kwargs):
149149
export_type = request_body.get('type', 'csv')
150150
filter_options = Q()
151151

152-
headings = filter(lambda field: field.name not in hidden, _get_headings(model_class))
153-
headings = list(headings)
152+
headings = list(_get_headings(model_class))
154153
for field in headings:
155-
field_name = field.name
154+
field_name = field
156155
try:
157156
filter_options = filter_options | Q(**{field_name + '__icontains': search_key})
158157
except Exception as _:
@@ -163,12 +162,12 @@ def export(request, **kwargs):
163162
for data in all_data:
164163
this_row = []
165164
for heading in headings:
166-
this_row.append(getattr(data, heading.name))
165+
this_row.append(getattr(data, heading))
167166
table_data.append(this_row)
168167

169168
df = pd.DataFrame(
170169
table_data,
171-
columns=tuple(heading.name for heading in headings))
170+
columns=tuple(heading for heading in headings))
172171
if export_type == 'pdf':
173172
base64encoded = get_pdf(df)
174173
elif export_type == 'xlsx':

0 commit comments

Comments
 (0)