I have created a table and have done Query Binding,and have created a button component and have done [configure event] script to download the table content in to excel file.
Based on your shared code, I would change the range() statement to only include the indices you want to download.
First 20: for row in range(0,20):
Last 20: for row in range(numRows-20,numRows):
Specific rows: for row in [ 1, 2, 3, 5, 7, 9 ]:
You might need to have checks to ensure you have 20 rows (numRows > 20).
# only download last 20 rows
numRows = len(data)
for row in range(numRows-20,numRows):
rowData = []
for col in range(len(headers)):
cell = data[row][headers[col]]
if hasattr(cell, 'value'):
rowData.append(cell.value)
else:
rowData.append(cell)
datasetData.append(rowData)
Thanks Shane, but if I need to download the table data page by page. how can I do that.
For example, there are 2 pages in the table [UI part] page 1 and page 2
[screenshot]
so, if I want to download page 2 table data, then how can I set the condition to download page 2 data only.
Note: table pages might increase further when more data are uploaded....
I think if you look at the table component, it has a property for 'activePage'.
You could probably use this, along with the total number of rows in the table, and the number of rows per page, to calculate the range of row indices to export.
# this assumes 'self' points to a table component
data = self.props.data
numRows = len(data)
numRowsPerPage = 25
activePage = self.props.pager.activePage
startRow = numRowsPerPage * (activePage - 1)
endRow = startRow + numRowsPerPage
if (endRow > numRows): endRow = numRows
for row in range(startRow, endRow):
# do the work here