Support the ongoing development of Laravel.io →
posted 10 years ago
Packages
Last updated 2 years ago.
0

What was wrong with:

What makes your package different/better? I use datatables all the time, its good stuff.

Last updated 2 years ago.
0

@that0n3guy

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:

  • Very simple interface to start with. Map database fields to columns and return results.
  • High customisation, nearly all classes are dependency injected and can be swapped out at run time for greater flexibility. (Wiki entries on this will be included in the near future)
  • Column interpretation and decoration over blade structures. Using the interpreter and decorator patterns it is very easy to chain both of these structures to manipulate the returned data in each column.
    • As well as this a closure can be used to grant greater control of returned data
  • Multi field sorting / column (introduced in 0.3.1)
  • Multi field search / column (introduced in 0.3.1)
  • Ability to easily create custom drivers for multiple databases. There is a mongo db implementation already in the package and in the future I plan to expand this to inorporate Cassandra and CouchDB.
  • Currently 99% code coverage on unit tests, module tests and acceptance tests.
  • No separation between collections and queries, both can be used exactly the same way.

###Components being worked on

  • Query manipulation at any point before results are collated.
  • Support for datatables 1.10.* input and return structures
  • View decorator to populate a column with the contents of a view
  • Custom decorator extensions that can be bound to the package at run time
  • Custom decorator/interpreter closures on the top level object

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.

Last updated 2 years ago.
0

Does it support all features of datatables (searching, ordering, adding/deleting/updating columns)?

Last updated 2 years ago.
0

psychonetic said:

Does it support all features of datatables (searching, ordering, adding/deleting/updating columns)?

It does

Supported features :

  • Full searching ( also regex searches with Mongo ) based on whether the column is searchable
  • Full ordering (multi field ordering and multi column sorting is supported)
  • Modify columns as much as you like with decorators etc.

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.

Last updated 2 years ago.
0

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..

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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

Last updated 9 years ago.
0

Hi is it compatible with datatables version 1.10?

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Daveawb daveawb Joined 14 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.