mariuszfoltak / angular2-datatable

DataTable - Simple table component with sorting and pagination for Angular2
202 stars 182 forks source link

Page number not reset to 1 on data update #22

Closed alex-mazzariol closed 8 years ago

alex-mazzariol commented 8 years ago

Scenario: I load a large dataset in the table (say 1000 rows), then the user switches to some non-first page (say page 10, pages have 15 elements), then another action in the page updates the dataset to a smaller one (say 50 elements) - there should be now 4 pages.

What happens is that the paginator does not show anymore, so the user can't switch back to page 1, and no rows are shown either - the UI seems broken.

Is there a way for me to set the page from the component, or a way to have the datatable go back to page 1 (or the mfActivePage)?

lacroixdavid1 commented 8 years ago

In case you haven't found a way, here is how i do it :

@ViewChild('dataTable') dataTable: DataTable;

public resetPagination() { this.dataTable.setPage(1, this.dataTable.rowsOnPage); }

<table width="1000" class="table table-hover" [mfData]="dataService.productList" #dataTable="mfDataTable" [mfRowsOnPage]="rowsOnPage" [mfActivePage]="activePage">

alex-mazzariol commented 8 years ago

This works, thank you!

vdoolla commented 6 years ago

@lacroixdavid1 & @alex-mazzariol - From last 10 months I am struggling to set active page to the datatable untitled Please review my above code snippet and let me know if you see any issues with usage of ViewChild. Any sort of help is really appreciable

lacroixdavid1 commented 6 years ago

@JavaCoder12 could you please reproduce in a plunker ill fix it for you. I see nothing wrong with your code its probably caused by where your method is called. Where do you call this method?

haf-elm commented 6 years ago

@JavaCoder12 Were you able to find a solution for your problem? I have the exact same problem => this.dataTable is undefined.