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

Extract filtered records #33

Open
patrickaglibut opened this issue May 31, 2018 · 11 comments
Open

Extract filtered records #33

patrickaglibut opened this issue May 31, 2018 · 11 comments

Comments

@patrickaglibut
Copy link

Good Day Sir,

Is there a way to extract all the table record, after filtering, etc, including the other paginated data?

Currently when using the datatable.all(true) option will only return the viewable part of the table but not the other data. Hoping for your response. Thanks.

Based on the screenshot below, I can only extract page 1 but i also need to extract pages 2 - 4.

image

@Holt59
Copy link
Owner

Holt59 commented May 31, 2018

Are you sure that you get only the first page? datatable.all(true) should return everything, even filtered data.

@patrickaglibut
Copy link
Author

patrickaglibut commented May 31, 2018

Yes Sir, only the viewable data. Unless I change the pageSize to say 20 then that is the only time i can get all the record.

image

Btw I'm using jquery 1.12 and here's the code i use to extract the data.

$(document).on('click','#btnextract', function() { var datatable = new DataTable(document.getElementById('MyTable'), { identify: 'id' }); var savedData = datatable.all(true); console.log(savedData); });

@Holt59
Copy link
Owner

Holt59 commented May 31, 2018

I cannot reproduce... If you go to this page: http://holt59.github.io/datatable/ and type datatable.all(true) in the console, you'll get 29 entries, whatever the current filters are on the example table.

Could you add more details regarding your code?

@patrickaglibut
Copy link
Author

here's the html file i used using your sample table. Thanks for checking on this Sir.

test.zip

@patrickaglibut
Copy link
Author

On your site when I tested what you have instructed, the datatable.all(true) extracts all data even though it is already filtered wherein it should only be 7 records.

image

@Holt59
Copy link
Owner

Holt59 commented May 31, 2018

Yes, this is the expected behavior currently, but it's different from having a single page.

@Holt59
Copy link
Owner

Holt59 commented May 31, 2018

In your code, you create a new DataTable to extract the data, this is not correct (you should never have two datatables on the same table). You should simple use the existing one:

$('#first-datatable-output table').datatable('select', true):

@patrickaglibut
Copy link
Author

I see, so the .all feature will extract data regardless of the filters used. Thanks for noting this and I'll try to create a function to extract only the filtered result. Any pointers would be very helpful. Thanks again.

@Holt59
Copy link
Owner

Holt59 commented May 31, 2018

You can use the filterIndex attribute:

// Retrieve the datatable object from the element.
var dt = $('#first-datatable-output table')[0].datatable; 

// Retrieve filtered data
var filteredData = [];
for (var i = 0; i < dt.filterIndex.length; ++i) {
    filteredData.push(dt.data[dt.filterIndex[i]]);
}

Not tested, but you get the idea.

@patrickaglibut
Copy link
Author

Noted and Thanks

@Holt59
Copy link
Owner

Holt59 commented May 31, 2018

I reopen this to keep it on the TODO list.

@Holt59 Holt59 changed the title Extract all records even paginated data Extract filtered records May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants