Pull data from only visible columns
Pull data from only visible columns
Hi there folks!
I am attempting to sort of recreate the "csv or excel" extend functions:
I am using datatables in a webviewer and those two are not quite working as I had hoped.
I only want to collect data from inputs from the filtered/found rows and visible columns.
I can get the below to work without issue, but as soon as i try to only collect data from visible columns only, I run into issues.
Does anybody have any tips or pointers they could pass my way?
Thanks!!!!!
```{
className: "fa-regular fa-file-export",
text: '<span style="font-size: 11px; font-family: Arial, sans-serif; margin-left: 11px;">Export found rows</span>',
action: function(e, dt, node, config) {
var table = $('#table').DataTable();
// Get filtered data
var filteredData = table.rows({ search: 'applied' }).data().toArray();
// Convert the array of objects to a JSON string
var jsonString = JSON.stringify(filteredData);
// Use FileMaker.PerformScript to call the script
FileMaker.PerformScript('getData', jsonString);
}
}```
This question has an accepted answers - jump to answer
Answers
I don't believe there is a way to use
rows().data()
to get only the visible columns. Likely this will require a two step process. See this example for one option:https://live.datatables.net/pupebunu/1/edit
First is gets the cell data using
cells().data()
with therow-selector
asnull
to get all the rows and thecell-selector
of:visible
for the visible columns. It uses the sameselector-modifier
of{ search: 'applied' }
.Next it uses
columns()
withcount()
to get the number of visible columns.Last is loops through the
cells().data()
array to refactor the single array into an array of arrays based on the visible column count.There might be better more efficient ways to do this.
Kevin
This is great!!!! Thank you!