mariuszfoltak / angular2-datatable

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

mfActivePage is not setting the value to the activePage filed of Datatable class #84

Open vdoolla opened 7 years ago

vdoolla commented 7 years ago

Hello All, I am using angular2-datatable: ^0.5.2 with angular/cli 1.0.0-beta.31 version and trying to set the activepage as below datatable Even though I am passing a positive number value for mfActivePage is not setting the value to the component. As per my business requirements I have to set active page number. If anyone knows the resolution for this issue please kindly post your suggestions.

sergeymorkovkin commented 7 years ago

Confirm. This one is reproducible.

vdoolla commented 7 years ago

Hi - Thank you for your response.

Yes I am still having the issue to set the activePage attribute. I am using the 0.5.2 version. Below is the code snippet of code how I am trying to set the activePage

image

mfRowsOnPage is working fine. Having issue with mfActivePage only. Please kindly let me know if you see any issue with my usage or do you have any work around to set the activePage.

reallyroy commented 7 years ago

We are seeing the same issue. Setting mfActivePage as shown above does not set the page as selected. Did anyone find a solution or work around for this?

ravikiranr26 commented 7 years ago

Any workaround for setting activePage from component ?

oosor commented 7 years ago

pageSizeOptions: number[] = [5, 10, 50]; rowsOnPage: number = 5; @ViewChild(DataTable) child: DataTable; //import {DataTable} from "angular2-datatable";

setNewPage(activePage: number) { //activePage: number, rowsOnPage: number this.child.setPage(activePage, this.rowsOnPage); }

vdoolla commented 6 years ago

@alienk1 - Thank you for sharing your solution but it is not working for me. Today I have tried your option with angular2-datatable: 0.5.2 and angular2-datatable: 0.6.0 verisons.

While calling this.child.setPage(this.currentActivePage,this.rowsOnPage); getting Exception Cannot read property 'setPage' of undefined.

As suggested above imported Datatable and placed @ViewChild attribute.

If the above solution is working for you could you please share the version numbers of both datatable and angular2/complier please.

hazielm commented 6 years ago

after response.json() call we need to call below function this.child.setPage(activePage, this.rowsOnPage);

vdoolla commented 6 years ago

@hazielm - When I am calling this.child.setPage(this.currentActivePage,this.rowsOnPage); getting Exception Cannot read property 'setPage' of undefined. Is it working for you ?.. What is the version you are using?

hazielm commented 6 years ago

"raw": "angular2-datatable@^0.6.0", "version": "0.6.0"

hazielm commented 6 years ago

import { DataTable } from 'angular2-datatable'; @ViewChild(DataTable) child: DataTable; after importing run this command "ng build" response => { this.data = response.json(); console.log(this.data); this.child.setPage(this.activePage,this.rowsOnPage); this.showDetails = true; },

guneetsinghbhatia commented 6 years ago

solution provided by @hazielm solved this problem for me.

vdoolla commented 6 years ago

@guneetsinghbhatia , @hazielm

untitled It would be grateful if anyone give me some hints to resolve ViewChild undefined issue.

PongsakronKanapan commented 5 years ago

@hazielm working for me

bickramSambahamphe2021 commented 3 years ago

i am still getting undefined in childDataTable. I configured as suggested by oosor commented on Aug 15, 2017 . still getting undefined while i printed in console during ngOnInt . I am bit confused where to place this.child.setPage(this.activePage,this.rowsOnPage)? Can anyone please help? I have placed it as blow: async getAllJobs() { if (!this.isAllDataFetched) { Helpers.setLoading(true); let tripData = await this._jobService.getCompletedJobs(); this.jobs = [...tripData];

  this.setDriverAndVahicle();
  this.sortJobArrayByTime();
  Helpers.setLoading(false);
  this.isAllDataFetched = true;

  this.child.setPage(this.activePage, this.rowsOnPage);

  return;
}
return;

}

bickramSambahamphe2021 commented 3 years ago

thank you every one i have fixed the issue as suggested by @hazielm