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

Need example with array as datasource #6

Closed
ocgltd opened this issue Dec 7, 2017 · 2 comments
Closed

Need example with array as datasource #6

ocgltd opened this issue Dec 7, 2017 · 2 comments
Assignees

Comments

@ocgltd
Copy link

ocgltd commented Dec 7, 2017

Could someone add an example/demo with a simple array as the data source? This question was posted on StackOverflow months ago and is unanswered. This would make ng2-ya-table usable for a wider audience.

@vitocmpl vitocmpl self-assigned this Dec 11, 2017
@vitocmpl
Copy link
Owner

vitocmpl commented Dec 11, 2017

The data source is an Observable in order to support pagination, ordering, and filtering server side.
For example, i wrote a simple .NET library to support this ng2-ya-table.DataSource.Core.

Anyway, you can manage a simple array in this way:

public datasource: any = (request: any): Observable<any> => {
    let page = (request.start / request.length) + 1;
    return Observable.of({
        recordsTotal: this.data.length,
        recordsFiltered: this.data.length,
        data: this.data.slice(request.length * (page - 1), request.length * page)
    });
}

The example support only the pagination.

I'm looking to implement a built-in local datasource to also support filtering and sorting.

@vitocmpl
Copy link
Owner

The latest version now supports the local data source natively.

<ng2-ya-table [options]="options" [columns]="columns" [datasource]="data" [paging]="paging">
</ng2-ya-table>
public data: Array<any> = [...]; //array of data

@vitocmpl vitocmpl closed this as completed Jan 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants