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

Integrate with laravel datatable #8

Closed
sakibwebworm opened this issue May 8, 2019 · 2 comments
Closed

Integrate with laravel datatable #8

sakibwebworm opened this issue May 8, 2019 · 2 comments

Comments

@sakibwebworm
Copy link

Hi , do you have any working example or do you know how it is possible to integrate it with Laravel datatables (yajira)

@noogen
Copy link
Contributor

noogen commented May 8, 2019

It's simple, just 3 lines of code as your controller method body:

$query = YourModel::query();
$dt = DataTables::of($query);
return $dt->make(true);

Demo: http://laratt.niiknow.org/home/contacts
Src: https://github.com/niiknow/laratt-api/blob/master/api/Controllers/DemoContactController.php#L68

Demo has extra code to support/demonstrate exporting.

As for using the component on the client-side, it's simply pointing/configuring the ajax.url to use the specific endpoint: https://github.com/niiknow/laratt-api/blob/5117bfae1273b31f95af6aa99c51aae7fc413d2f/resources/js/components/DataTableNet.vue#L148

I calculate the route as:

url: that.$app.apiRoute(that.rName, that.rPath),

In reality, this is the resulting URL: https://laratt.niiknow.org/api/v1/democontact/example?x-tenant=test&x-api-key=demo123

Or you can play around with the API at: https://laratt.niiknow.org/api/documentation

Phewwww, that was a lot of work for a simple end-to-end demo of 3 lines of code that you can simply write as return DataTables::of(YourModel::query())->make(true);

@noogen noogen pinned this issue May 9, 2019
@noogen
Copy link
Contributor

noogen commented Feb 9, 2022

Old issue with no updates.

@noogen noogen closed this as completed Feb 9, 2022
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