What was wrong with:
What makes your package different/better? I use datatables all the time, its good stuff.
I found the other packages unnecessarily convoluted, with large portions of code untested, also I found the architecture of the packages to be restrictive.
###Reasons this package differs from others:
###Components being worked on
I needed a package that could be used to display, sort and manage relational data across many tables in one datatable, that could easily switch out database drivers as well as supporting all the client side features that datatables offers.
I'm also open to any suggestions and will be actively developing this package for a long time to come, I have been using its predecessor extensively for some time and have a lot of experience dealing with datatables on the client side.
One feature I will be working on once the code is at a major release is a client side tie in with Backbone.js to compliment the Backbone.js plugin I'm currently developing for Datatables that doesn't just convert models to JSON.
Does it support all features of datatables (searching, ordering, adding/deleting/updating columns)?
psychonetic said:
Does it support all features of datatables (searching, ordering, adding/deleting/updating columns)?
It does
Supported features :
Not sure what you mean by adding/deleting/updating columns server side. If you mean does it build a view for you, no it doesn't at the moment, I want to keep the front end implementation up to the developer, though this may be something I add in the future.
Additional re: adding/deleting/updating
The package works with the client side mDataProp
setting on the column or from 1.10.x onwards, support will be for the data
and name
attributes from the client side. In essence this allows support for client side re-ordering, removal, addition and updating of columns.
Does your package support using joins or searching in relations? That's where I always have trouble with, using my own datatables class. I now use a join and some aliases to search/filter on relations, but it isn't really pretty.
For example, I have a table with thousands of ads, created by a lot of different companies. And I want to be able to search on the columns from the ads table, but also the name of the related company. Using a collection to filter after is loading to much data..
barryvdh said:
Does your package support using joins or searching in relations? That's where I always have trouble with, using my own datatables class. I now use a join and some aliases to search/filter on relations, but it isn't really pretty.
For example, I have a table with thousands of ads, created by a lot of different companies. And I want to be able to search on the columns from the ads table, but also the name of the related company. Using a collection to filter after is loading to much data..
In theory, yes, joins and searching by relation is supported (but both untested).
I have used a join to return results using this package however the returned row count screws up when a one to many or many to many relationship is joined (though it does work in the table). Eloquent relationships are something I very much want to support.
###Query builder joins
$datatable->query(DB::table('users')->join('roles', 'roles.user_id', '=', 'users.id'));
Does work and is fully sortable and searchable. This is untested at present though I did build the package with being able to use joins and multiple tables in mind, this is something I very much wish to be a stable feature of this package.
###Eloquent relationships
using an eloquent relationship should work along these lines (very much untested code below)
$datatable->query(with(new User())->with('role'));
$datatable->columns(array(
"first_name",
"last_name",
"role.name"
));
I think both of the above features should definitely be supported. If you find there are problems please raise an issue, in the mean time I'll be looking at writing tests for these and fully implementing them for the next release.
barryvdh said:
Does your package support using joins or searching in relations? That's where I always have trouble with, using my own datatables class. I now use a join and some aliases to search/filter on relations, but it isn't really pretty.
For example, I have a table with thousands of ads, created by a lot of different companies. And I want to be able to search on the columns from the ads table, but also the name of the related company. Using a collection to filter after is loading to much data..
Ok so I just wrote some module tests for joins using the query builder with an assuringly high level of success.
Assuming there is a many to many relationship between users
and roles
using a role_user
pivot table, the following code works with correct data, but incorrect row counts. I think to get the row counts working I'm going to need to do the count as a sub query based on the top level table. Thanks Barry, your post has got me thinking!
$datatable->query(DB::table('users')
->select(DB::raw('group_concat(roles.role) as role, first_name'))
->leftJoin('role_user', 'users.id', '=', 'role_user.user_id')
->leftJoin('roles', 'role_user.role_id', '=', 'roles.id')
->groupBy('users.id')
);
$datatable->columns(array(
"first_name",
"role"
));
return $datatable->result();
I hope you'll agree that this is a very clean way to be able to used join data albeit count data is currently incorrect.
Hi Daveawb,
What am I doing wrong. I just copied your 'ease of use' code and placed it in my route. When browsing to this route I get a MethodNotAllowedHttpException:
Open: C:\xampp\htdocs\swm\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php * @param array $others * @return void * * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException */ protected function methodNotAllowed(array $others) { throw new MethodNotAllowedHttpException($others); }
what's wrong here?
Steps taken:
1 added "daveawb/datatables": "dev-master" to composer.json
2 composer update
3 added to alliases 'Datatable' => 'Daveawb\Datatables\Facades\Datatable'
4 copy-paste code in route
5 browse to that route ->error
6 composer dump autoload
7 try again -> same error
regards,
Dave
Hi is it compatible with datatables version 1.10?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community