Export only selected data from Table to Excel [Ignition Perspective]

Hello team,
Module: Perspective
Component: TABLE
Database used: MSSQL

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.

[screenshot]

Currently all data from the table is getting exported to excel file.

-> Is there any method for downloading the Table data like the following:

  1. Download only first page table data shown on the screen
    [screenshot]

  2. Download only latest 20 dataset from table

Code written for exporting table data to excel:

code.txt (700 Bytes)

Thanks in Advance,
Goutham Rao Y

Hi-

There are probably several ways of doing this.

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)

HTH.
-Shane

1 Like

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]
image

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

HTH.
-Shane

1 Like