Giter Club home page Giter Club logo

laravel-datatables's Introduction

jQuery DataTables API for Laravel

Join the chat at https://gitter.im/yajra/laravel-datatables Donate Donate

Laravel 4.2|5.x|6|7|8|9|10|11 Latest Stable Version Continuous Integration Static Analysis

Total Downloads License

Laravel package for handling server-side works of DataTables jQuery Plugin via AJAX option by using Eloquent ORM, Fluent Query Builder or Collection.

use Yajra\DataTables\Facades\DataTables;

return DataTables::eloquent(User::query())->toJson();
return DataTables::query(DB::table('users'))->toJson();
return DataTables::collection(User::all())->toJson();

return DataTables::make(User::query())->toJson();
return DataTables::make(DB::table('users'))->toJson();
return DataTables::make(User::all())->toJson();

Sponsors

DataTables JetBrains.com Blackfire.io

Requirements

Documentations

Laravel Version Compatibility

Laravel Package
4.2.x 3.x
5.0.x 6.x
5.1.x 6.x
5.2.x 6.x
5.3.x 6.x
5.4.x 7.x, 8.x
5.5.x 8.x
5.6.x 8.x
5.7.x 8.x
5.8.x 9.x
6.x 9.x
7.x 9.x
8.x 9.x
9.x 10.x
10.x 10.x
11.x 11.x

Quick Installation

composer require yajra/laravel-datatables-oracle:"^11"

Service Provider & Facade (Optional on Laravel 5.5+)

Register provider and facade on your config/app.php file.

'providers' => [
    ...,
    Yajra\DataTables\DataTablesServiceProvider::class,
]

'aliases' => [
    ...,
    'DataTables' => Yajra\DataTables\Facades\DataTables::class,
]

Configuration (Optional)

php artisan vendor:publish --provider="Yajra\DataTables\DataTablesServiceProvider"

And that's it! Start building out some awesome DataTables!

Debugging Mode

To enable debugging mode, just set APP_DEBUG=true and the package will include the queries and inputs used when processing the table.

IMPORTANT: Please make sure that APP_DEBUG is set to false when your app is on production.

PHP ARTISAN SERVE BUG

Please avoid using php artisan serve when developing with the package. There are known bugs when using this where Laravel randomly returns a redirect and 401 (Unauthorized) if the route requires authentication and a 404 NotFoundHttpException on valid routes.

It is advised to use Homestead or Valet when working with the package.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-datatables's People

Contributors

ansient avatar apreiml avatar arkhas avatar bingbig avatar carusogabriel avatar darkaonline avatar drahosistvan avatar elfsundae avatar ethaizone avatar frknakk avatar hiendv avatar hpacleb avatar intech avatar jidago avatar lloricode avatar markvaughn avatar morinohtar avatar openvast avatar ozankurt avatar pettercastro avatar pimlie avatar ridaamirini avatar schonhoff avatar sebdesign avatar selecod avatar sharifzadesina avatar stylecibot avatar tortuetorche avatar vladkucherov avatar yajra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-datatables's Issues

Just a few words

Many thanks for your wonderfull packadge !

Just a few words about the doc :

  • could you mention that your packadge IS NOT Oracle exclusive, but works also with MySQL and ???
  • other packadges (like Chumper) works with Datatables 1.9 only. Could you mention that your packadge works (very well !!) with Datatables 1.10
  • I just encounter a little problemn with ->make() in place of ->make(true) with Datables 1.10. You use both of them in the doc but you doesn't explain the difference. I found it in the threads, but it would be easier.

Last, mention your packadge to Eric Barnes of Laravel-news !!! ( Twitter at @ericlbarnes.)

Paguemaou

Paging broken after updating

I just updated to 4.1.0 to get column searching working. But now I loads all te results in the first page. Clicking on the 2nd page only loads the number of rows selected. Clicking on the first page again, all rows are loaded again. Looks like limit is not working.

The paging is working fine and also changes when I change the number of shown records per page.

Error: Undefined index: columns

Hi,

Thanks for creating this package, it's exactly what I would need... only issue is that I cannot seem to get it working. I keep on receiving this error:

ErrorException in BaseEngine.php line 918: Undefined index: columns

Any thought on how to get around this?

screen shot 2015-05-12 at 14 35 38

Thanks in advance!

New Update v5.1.1 Error My Codes !

ErrorException in BaseEngine.php line 968:
Undefined index: columns

$data = Equipment::join('equipment_lang', 'equipment_lang.parentid', '=', 'equipment.id')
->select(array('equipment.id','equipment_lang.title','equipment_lang.product_type'))
->orderBy('equipment.position', 'ASC')->where('equipment_lang.lang', 'tr');

          return Datatables::of($data)->make();

how to fix ('Undefined index: columns')

production.ERROR: exception 'ErrorException' with message 'Undefined index: columns' in vendor/yajra/laravel-datatables-oracle/src/yajra/Datatables/Engine/BaseEngine.php:919

Eloquent issue

First of all, your package is amazing simple. I have a questions so far:

I can't use an Eloquent model like this:

return Datatables::of(Project::with('owner'))->make();

// ErrorException in Datatables.php line 285: Invalid argument supplied for foreach()

I'm on Laravel 5, any idea?

Thanks and regards!

caseInsensitive search not working: what i'm missing??

Hi Arjay,

i cannot figure how to make caseInsensitive search work. What i'm doing wrong?

//In my controller
public function index(Request $request)
{
    $ulogs = Ulog::select(['id','id_utente','ip','url', 'method', 'action', 'tipo', 'messaggio']);
    return Datatables::of($ulogs)->make();
}

//In my view
    $(document).ready(function() {
        $('#ulogs-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: '{{ url("ws/ulogs") }}',
            order: [ [0, "desc"] ],
            lengthMenu: [ [10, 25, 50, -1], [10, 25, 50, "+"] ],
            language: {
                url: "https://cdn.datatables.net/plug-ins/1.10.7/i18n/Italian.json"
            },
            search: {
                caseInsensitive: true
            },
            searchHighlight: true,
            responsive: true,
            columnDefs: [{
                render: function(data, type, row){
                    return '<abbr title="' + data + '"><span class="fa fa-expand"></span></abbr>';
                },
                targets: 3
            }, {
                render: function(data, type, row){
                    return data;
                },
                targets: 7
            }]
        });
    });

Thank you!!

Sort problem with count

Hello, there is a problem with the datatable sorting a field when you use count(*) with Alias. any help plz.

News Update My table error !

My Error :
ErrorException in Datatables.php line 329:
Undefined offset: 4

My Controller :

$data = News::join('news_lang', 'news_lang.parentid', '=', 'news.id')
->select(array('news.id','news.typew','news_lang.title','news.date'))
->orderBy('news.date', 'DESC')->where('news_lang.lang', 'tr');

         return Datatables::of($data)
        ->edit_column('title', '{{str_limit($title, $limit = 45, $end = "...")}}')
        ->edit_column('typew', '{{$typew == "news" ? "news":( $typew=="social" ? "social" :( $typew=="voice" ? "voice":"none"))}}')

        ->add_column('actions', '<a   data-button="{{{ URL::to(\'admin/news/\' . $id . \'/edit\' ) }}}"    class="btn btn-success btn-sm event_button" ><span class="glyphicon glyphicon-pencil"></span> </a>
            <a   data-button="{{{ URL::to(\'admin/media/\' . $id . \'/get\' ) }}}"    class="btn btn-success yellow btn-sm event_button" ><span class="glyphicon glyphicon-picture"></span></a>
                <a  id="{{$id}}" data-toggle="confirmation" data-original-title="{{ Lang::get("admin/news.confirma_delete") }}"  class="btn btn-sm btn-danger item_deletew"><span class="glyphicon glyphicon-trash"></span></a>
                <input type="hidden" name="row" value="{{$id}}" id="row">')


        ->make();

My jquery:

oTable = $('#table').dataTable({
"sDom" : "<'row'<'col-md-6'l><'col-md-6'f>r>t<'row'<'col-md-6'i><'col-md-6'p>>",
"sPaginationType" : "bootstrap",

  "bProcessing" : true,
  "bServerSide" : true,
  "sAjaxSource" : "{{ URL::to('admin/news/data/') }}",
  "fnDrawCallback" : function(oSettings) {
     Metronic.init();
    UIConfirmations.init(); 

get data :

ata?sEcho=1&iColumns=5&sColumns=%2C%2C%2C%2C&iDisplayStart=0&iDisplayLength=10&mDataProp_0=0&sSearch_0=&bRegex_0=false&bSearchable_0=true&bSortable_0=true&mDataProp_1=1&sSearch_1=&bRegex_1=false&bSearchable_1=true&bSortable_1=true&mDataProp_2=2&sSearch_2=&bRegex_2=false&bSearchable_2=true&bSortable_2=true&mDataProp_3=3&sSearch_3=&bRegex_3=false&bSearchable_3=true&bSortable_3=true&mDataProp_4=4&sSearch_4=&bRegex_4=false&bSearchable_4=true&bSortable_4=true&sSearch=&bRegex=false&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&_=1427536607841

Error: Undefined property $columns on hasManyThrough relationship

There seems to be an issue when working with hasManyThrough relationships. This is my query:

$campaigns = User::find($user_id)->campaignDetails()->select(['user_campaigns.user_id','campaign_details.campaign_id as as','campaign_name','campaign_status']);
        return Datatables::of($campaigns)->make(true);

public function campaignDetails()
    {
        return $this->hasManyThrough('App\CampaignDetail','App\UserCampaign','user_id','campaign_id');
    }

This is the code that seems to be causing the problem. Line 298 in Datatables\Datatables.php:
$this->columns = $this->query_type == 'eloquent' ? $this->query->getQuery()->columns : $this->query->columns;

But it seems that Eloquent is not returning you the columns and that's why I'm guessing it's failing? Any workaround?

Option caseInsesitive is not working on server-side.

Hi!

When I set the option search.caseInsensitive in my view, the query generated are not respecting this parameter. More about this parameter, can be found here.

So in my view, with this javascript:

        $('#basesRateioTable').DataTable({
            "serverSide": true,
            "processing": true,
            "ajax": "{!! URL::action('Admin\BaseRateioController@consulta') !!}",
            "search": {
                "caseInsensitive": true
            },
            "order": [[ 2, "desc" ], [3, 'asc']],
          //more ommited...

The option caseInsensitive: true is still working like caseInsensitive: false (default behavior). The generated URL when this option is configured to false:

consulta?draw=4&columns%5B0%5D%5Bdata%5D=&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=false&columns%5B0%5D%5Borderable%5D=false&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=id&columns%5B1%5D%5Bname%5D=id&columns%5B1%5D%5Bsearchable%5D=false&columns%5B1%5D%5Borderable%5D=false&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=ano&columns%5B2%5D%5Bname%5D=ano&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=descricao&columns%5B3%5D%5Bname%5D=descricao&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=codigo&columns%5B4%5D%5Bname%5D=codigo&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B5%5D%5Bdata%5D=codigo_cliente&columns%5B5%5D%5Bname%5D=codigo_cliente&columns%5B5%5D%5Bsearchable%5D=true&columns%5B5%5D%5Borderable%5D=true&columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B6%5D%5Bdata%5D=oferta&columns%5B6%5D%5Bname%5D=oferta&columns%5B6%5D%5Bsearchable%5D=true&columns%5B6%5D%5Borderable%5D=true&columns%5B6%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B6%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B7%5D%5Bdata%5D=os&columns%5B7%5D%5Bname%5D=os&columns%5B7%5D%5Bsearchable%5D=true&columns%5B7%5D%5Borderable%5D=true&columns%5B7%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B7%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B8%5D%5Bdata%5D=janeiro&columns%5B8%5D%5Bname%5D=janeiro&columns%5B8%5D%5Bsearchable%5D=true&columns%5B8%5D%5Borderable%5D=true&columns%5B8%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B8%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B9%5D%5Bdata%5D=fevereiro&columns%5B9%5D%5Bname%5D=fevereiro&columns%5B9%5D%5Bsearchable%5D=true&columns%5B9%5D%5Borderable%5D=true&columns%5B9%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B9%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B10%5D%5Bdata%5D=marco&columns%5B10%5D%5Bname%5D=marco&columns%5B10%5D%5Bsearchable%5D=true&columns%5B10%5D%5Borderable%5D=true&columns%5B10%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B10%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B11%5D%5Bdata%5D=abril&columns%5B11%5D%5Bname%5D=abril&columns%5B11%5D%5Bsearchable%5D=true&columns%5B11%5D%5Borderable%5D=true&columns%5B11%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B11%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B12%5D%5Bdata%5D=maio&columns%5B12%5D%5Bname%5D=maio&columns%5B12%5D%5Bsearchable%5D=true&columns%5B12%5D%5Borderable%5D=true&columns%5B12%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B12%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B13%5D%5Bdata%5D=junho&columns%5B13%5D%5Bname%5D=junho&columns%5B13%5D%5Bsearchable%5D=true&columns%5B13%5D%5Borderable%5D=true&columns%5B13%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B13%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B14%5D%5Bdata%5D=julho&columns%5B14%5D%5Bname%5D=julho&columns%5B14%5D%5Bsearchable%5D=true&columns%5B14%5D%5Borderable%5D=true&columns%5B14%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B14%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B15%5D%5Bdata%5D=agosto&columns%5B15%5D%5Bname%5D=agosto&columns%5B15%5D%5Bsearchable%5D=true&columns%5B15%5D%5Borderable%5D=true&columns%5B15%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B15%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B16%5D%5Bdata%5D=setembro&columns%5B16%5D%5Bname%5D=setembro&columns%5B16%5D%5Bsearchable%5D=true&columns%5B16%5D%5Borderable%5D=true&columns%5B16%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B16%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B17%5D%5Bdata%5D=outubro&columns%5B17%5D%5Bname%5D=outubro&columns%5B17%5D%5Bsearchable%5D=true&columns%5B17%5D%5Borderable%5D=true&columns%5B17%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B17%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B18%5D%5Bdata%5D=novembro&columns%5B18%5D%5Bname%5D=novembro&columns%5B18%5D%5Bsearchable%5D=true&columns%5B18%5D%5Borderable%5D=true&columns%5B18%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B18%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B19%5D%5Bdata%5D=dezembro&columns%5B19%5D%5Bname%5D=dezembro&columns%5B19%5D%5Bsearchable%5D=true&columns%5B19%5D%5Borderable%5D=true&columns%5B19%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B19%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=2&order%5B0%5D%5Bdir%5D=desc&order%5B1%5D%5Bcolumn%5D=3&order%5B1%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=Hello&search%5Bregex%5D=false&_=1427395532984

Search

Search is giving me this error

DataTables warning: table id=table - Ajax error. For more information about this error, please see http://datatables.net/tn/7

here is my view call:

$(document).ready(function() {
oTable =
    $('#table').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": "{{ URL::to('admin/api/job_titles') }}",
        "columns": [
            {data: 'name', name: 'name'},
            {data: 'description', name: 'description'},
            {data: 'updated_at', name: 'updated_at'},
            {data: 'actions', name: 'actions'}
        ]
    });
});

Everything is running good!

Sorting edited columns

Sorry @yajra, but I have another question concerning sorting.
I selected some Ids for a hand full of columns which I edited afterwards.

Here is an example:

$projects = Project::select([
    'id',
    'username',
    'identity',
]);

return Datatables::of($projects)
    ->editColumn('identity', function($projects) {
        // Some magic number adaption
        $newValue = $this->getIdent($projects->identity);
        return $newValue
    })->make();

The problem on this is approach is that sorting the datatables uses the selected values from the $projects object and doesn't take edited columns into account, right?

So if I have 3 entries where the identity field in the database are 10, 20 and 30. After some magic number adaption they will be presented as 901, 800, 1904. So when I sort the results, I get the wrong order, right? Any solution for that?

Thanks and kind regards!

[v5.0] Add support for Collection as data source

WIP: Add support for Laravel's Collection object as data source for Datatables.

Inviting beta testers and contributors to join the fun. ^_^. Please checkout develop branch.

Note:
v5.0 Initial plan:

  • Drop support for Laravel 4 [will depend on demand].
  • Support for Laravel 4 will continue on v3.x branch but Collection and new features will not be added.
  • Drop support for Datatables v1.9 and below.

removeColumn doesn't remove the column from the sColumns array

I have an issue where if i use removeColumn, the column will still be included in the sColumns array.

Using removeColumn will remove the column from the data array, but will it will still be included in the sColumns part.

The result is that when reordering, it will order by the wrong column.

Sorry for the vague explanation.

Not able to get the search working

yajra, really like the package. Only i cannot get the search to work. I want to search on model name, wich i got trough a join. Is this possible?

Everything works fine, the ID's get converted into model names in the table. But when i want to search i on a model name, i get an error:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'name' in where clause is ambiguous (SQL: select count(*) as aggregate from (select '1' as row_count frompartleft joinmodelonmodel.model_id=part.model_idwhere (LOWER(name) LIKE %fzr%)) count_row_table)

My code:

$parts = Part::select('part.part_id', 'model.name') ->leftJoin('model', 'model.model_id','=','part.model_id');

JS:

oTable = $('#table').DataTable({
"processing": true,
"serverSide": true,
"ajax": "{{ URL::route('part.datatables') }}",
"columns": [
{data: 'part_id', "orderable": false, "searchable":false, name: 'part_id'},
{data: 'name', "orderable": false, "searchable":true, name: 'name'}
]
});

I"m not sure if i`m making an mistake, or that its just not possible.

i can't use addColumn in datatables(l5)

when use addColumn ,the datatable has somethings wrong
js datatables setting: "bServerSide": true(datatables 1.9.4)
php error see images
20150429174402
20150429174413

if "bServerSide": false, Pagination just has one page ,how to do?
20150429174451

And use datatables 1.10.5.the problem still exists

see here

if i don‘t add html class addClass, datatables hasn't problem ,return json has addColumn "222", when add html class"addColumn" an refresh web, the datatables has error

20150429182021
20150429182008
20150429181927

L5 support

Hi Arjay,

what about L5 support?

thank you ;-)

Possible errors in the code

Hi,
I tried this package with Laravel 5 and DT 1.10. Works well, but I think there is a error in 2 places in Datatables class:

$copy_this->wildcardLikeString(....

I assume that this should be

$this->wildcardLikeString(....

or we need variable

$copy_this = $this;

Thanks

fatal Exception

troubled with below error

at HandleExceptions->fatalExceptionFromError(array('type' => '1', 'message' => 'Class 'Bllim\Datatables\Facade\Datatables' not found', 'file' => '/home/sites/my-laravel/app/Http/Controllers/DataController.php', 'line' => '96')) in HandleExceptions.php line 116

whereHas query and error in count query

I have table users and roles, relation many to many. Now I need in users list display all users with role, for example "admin".
Query:

$users = User::select(array( 'users.id', 'users.status', 'users.first_name', 'users.last_name', 'users.email', 'users.last_seen'))
->whereHas('roles', function($q) {
    $q->where('id', '=', 'admin');
})->with('roles');

This query is ok when not use it for Datatables, but when I add ::of($users) then I have exception:

Column not found: 1054 Unknown column 'roles' in 'where clause' (SQL: select count(*) as aggregate from (select '1' as row_count from `users` where (select count(*) from `roles` inner join `role_user` on `roles`.`id` = `role_user`.`role_id` where `role_user`.`user_id` = `users`.`id` and `name` = admin) >= 1 and `roles` LIKE %1%) count_row_table)
/framework/src/Illuminate/Database/Connection.php#620

Query without hasMany works fine, but filters only on users table.

I use Laravel 5, newest version of Datatables library and javascript plugin. I'm new in Laravel world, maybe I do it wrong way.

Quick search not working

Hey there,

I'm using the latest version of the package (4.2.0) but don't get quick search working. When I use client-side processing everything works fine. But when using server-side processing the table does not update.

My server-side processing looks like this:

$profiles = Customer::leftJoin('presets','presets.id','=','customers.support_status_id')
->leftJoin('partners','partners.id','=','customers.partner_id')
->select(['customers.reference_number', 'customers.name as name1', 'customers.postcode', 'customers.city', 'presets.value', 'partners.name as name2', 'customers.id']);

return Datatables::of($profiles)->make();

Any idea what could cause the issue?

Thanks a lot!

Exclude table ID from search.

Hi!

I realized a strange behavior when searching. When I search using the search field in datatable, the column ID is using in query. Take a look:

select *
          from po_base_rateio
         inner join po_anos
            on po_anos.id = po_base_rateio.ano_id
         inner join po_direcionadores
            on po_direcionadores.id = po_base_rateio.direcionador_id
         inner join po_atividades
            on po_atividades.id = po_base_rateio.atividade_id
         where (id LIKE '%1034%' or po_anos.ano LIKE '%1034%' or
               po_direcionadores.descricao LIKE '%1034%' or
               po_atividades.codigo LIKE '%1034%' or an8 LIKE '%1034%' or oferta LIKE '%1034%' or
               os LIKE '%1034%' or janeiro LIKE '%1034%' or fevereiro LIKE '%1034%' or
               marco LIKE '%1034%' or abril LIKE '%1034%' or maio LIKE '%1034%' or junho LIKE '%1034%' or
               julho LIKE '%1034%' or agosto LIKE '%1034%' or setembro LIKE '%1034%' or
               outubro LIKE '%1034%' or novembro LIKE '%1034%' or dezembro LIKE '%1034%')
         order by po_anos.ano desc, po_base_rateio.direcionador_id asc;

At where clause, the query is using an ID to search, but I don't want to search using ID.
id LIKE '%1034%'

My view:

        var table = $('#basesRateioTable').DataTable({
            "serverSide": true,
            "processing": true,
            "ajax": "{!! URL::action('Admin\BaseRateioController@consulta') !!}",
            "columns": [    
                {data: 'ano', name: 'anos.ano'},
                {data: 'descricao', name: 'direcionadores.descricao'},
                {data: 'codigo', name: 'atividades.codigo'},
                {data: 'an8', name: 'an8'},
                {data: 'oferta', name: 'oferta'},
                {data: 'os', name: 'os'},
                {data: 'janeiro', name: 'janeiro'},
                {data: 'fevereiro', name: 'fevereiro'},
                {data: 'marco', name: 'marco'},
                {data: 'abril', name: 'abril'},
                {data: 'maio', name: 'maio'},
                {data: 'junho', name: 'junho'},
                {data: 'julho', name: 'julho'},
                {data: 'agosto', name: 'agosto'},
                {data: 'setembro', name: 'setembro'},
                {data: 'outubro', name: 'outubro'},
                {data: 'novembro', name: 'novembro'},
                {data: 'dezembro', name: 'dezembro'}
            ],            
            "language": {
                "url": "{!! URL::to('plugins/datatable/js/Portuguese.json') !!}"
            }
        });

And my Controller:

            $colunas = ['base_rateio.id','anos.ano', 'direcionadores.descricao', 'atividades.codigo', 'base_rateio.an8', 'base_rateio.oferta',
                        'base_rateio.os', 'base_rateio.janeiro', 'base_rateio.fevereiro', 'base_rateio.marco', 'base_rateio.abril',
                        'base_rateio.maio', 'base_rateio.junho', 'base_rateio.julho', 'base_rateio.agosto', 'base_rateio.setembro',
                        'base_rateio.outubro', 'base_rateio.novembro', 'base_rateio.dezembro'];

            $basesRateio = BaseRateio::getBaseRateioOrdenadoAno()->select($colunas);
            return Datatables::of($basesRateio)->make(true);

The search in my Model:

        return BaseRateio::join('anos', 'anos.id', '=', 'base_rateio.ano_id')
                         ->join('direcionadores', 'direcionadores.id', '=', 'base_rateio.direcionador_id')
                         ->join('atividades', 'atividades.id', '=', 'base_rateio.atividade_id')
                         ->orderBy('anos.ano', 'desc')
                         ->orderBy('base_rateio.direcionador_id', 'asc');

I don't know if this is bug, because I am not specifying the ID column anywhere, and the component still use this column as search parameter.

Row Numbering on Page Click

I need to add a serial number column to all rows. How can I access the start page from data-table.
public function getData() {
$providers = Provider::select(['fname','lname','email', 'type', 'status', 'created_at']);
return Datatables::of($providers)
->addColumn('slno','start page + 1',1)
->addColumn('fullname', function($model) {
return $model->fullname;
},2)
->editColumn('status', '{!! ucfirst($status) !!}')
->removeColumn('fname')
->removeColumn('lname')
->make();
}

Searching doesn't work with POST routes

Hi,

My Javascript code:

$('#list').dataTable({
    "sAjaxSource":"/complete_list",
     "sPaginationType": "bootstrap_full_number",
    "bAutoWidth": false,
    "iDisplayLength": 25,
    "deferRender": true,
    "bProcessing": true,
    "bServerSide": true,
    "sServerMethod": "POST",
    "order": [[0, "desc"]],
});

My route:

Route::get('/complete_list', array('uses' => 'testController@load_Datatable'));

When I change the GET method in my route and in my JS, the searching works well. But when I use POST; the search doesn't work. Return all the rows.

Is my code wrong... or is a fail of the package?

Regards and thanks for your amazing job:)

Sorting and filtering with relations

First of all, great package! It really saves me a lot of time.

My problem is that if i have entities with relations between them such as an article having one auhtor I can't sort the table of articles based on the authors name since I get an error like:

Column not found: 1054 Unknown column 'author' in 'order clause' (SQL: select * from `articles` order by `author` asc limit 10 offset 0)

// From controller
$articles = Article::with('author');

return Datatables::of($articles)->make(true);

I have the following in my Article model:

public function author()
{
    return $this->belongsTo('App\Author');
}

So my question is, how can I modify the default behaviour to take relations in perspective when sorting and filtering a data table.

Oracle invalid identifier when use filter

Hi!

I installed the plugin and it works pretty well! Thanks! However, when I try to filter my records, I get an Oracle error: Invalid Identifier for columns.

I debugged the problem and I saw that the plugin was putting my tables prefix before column. This happens here: https://github.com/yajra/laravel-datatables-oracle/blob/master/src/yajra/Datatables/Datatables.php#L606

// line removed
$column = $db_prefix . $column;

So, I remove the line and it worked!

I don't know if this is a bug, but I want to let you know about this problem. If you think this is not a bug and you have another solution or if I am doing something wrong, please, let me know.

Display Row Number

I tried this. But sql error. I am using my_sql.
Displaying a serial number as the first column is required in most table. But not successfull, till now.

public function getData() {
DB::statement(DB::raw('set @rownum=0'));
$providers = Provider::select(['@rownum:=@rownum+1 row_num','fname','lname','email', 'type', 'status', 'created_at']);
return Datatables::of($providers)
->addColumn('slno','row_num',1)

->addColumn('fullname', function($model) {
return $model->fullname;
},2)
->addColumn('Actions','Action Here')
->editColumn('status', '{!! ucfirst($status) !!}')
->removeColumn('fname')
->removeColumn('lname')
->make();
}

Error: MySQL alias error

Hello!
Thanks for creating this package!
I get an error when takin field from the database through an alias.

$advs = Post::select([
'id',
'title as post_title',
]);

Error:

"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as `post_title` asc limit 10 offset 0' at line 1 (SQL: select `posts`.`id`, `posts`.`title` as `post_title` from `posts`  order by `title` as `post_title` asc limit 10 offset 0)"

Please, help me to solve this problem.

How can I use if else in select query?

I want to When employees.type == "Office" then Join Office table, and When employees.type == "Project" then Join Project table, Is it possible for every table row check this condition?

My query is like that..

$employeetbl = Employee::Join('projects','employees.type_id','=','projects.id') ->select(array('employees.name','employees.type','projects.project_name','employees.join_date','employees.comment','employees.id AS eid'));
return Datatables::of($employeetbl)
->make();

About searching and ajax calling method

Sometimes when i abuse using search to much, the datatables response with 302, and the alert datatable error 1 popout..
Sometimes it's get unauthorized, alert datatable error 7 popout
How to prevent these?

When i search in the forum, it stated that laravel doing it on purpose for security when there are to many same GET request happen
What happen if i change the AJAX method to POST? Will the datatable run smoothly..
thank you :)

Firebug Warning

While debugging with firebug, I was able to get data with warning:
DataTables warning: table id=users-table - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

Search Option not working when I used Join Query.

When I add join query Like that :

$Employee = Employee::leftJoin('projects','employees.type_id','=','projects.id')
->select(array('employees.name','employees.type','projects.project_name','employees.join_date','employees.comment','employees.id AS eid'));
return Datatables::of($Employee)
->edit_column('eid','


')
->make(true);

Datatable work fine as well, But when I press the any key at search box it's showing error!!

The error is :

" QueryException in Connection.php line 624:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'eid' in 'where clause' (SQL: select count(*) as aggregate from (select '1' as row_count from employees left join projects on employees.type_id = projects.id where (LOWER(name) LIKE %t% or LOWER(type) LIKE %t% or LOWER(project_name) LIKE %t% or LOWER(join_date) LIKE %t% or LOWER(comment) LIKE %t% or LOWER(eid) LIKE %t%)) count_row_table) "

Where is my mistake I can't understand it. How can I fix the problem.

Mysql protected words

Hi,
I've run into a problem with column names and search part of the package. There is a problem with raw query column names and protected MySQl words (like order for example).

if ($this->isCaseInsensitive()) {
                            $query->orWhere($connection->raw('LOWER(' . $cast_begin . $column . $cast_end . ')'),
                                'LIKE', strtolower($keyword));
                        } else {
                            $query->orWhere($connection->raw($cast_begin . $column . $cast_end), 'LIKE', $keyword);
                        }

Something like this works well

 $column = '`' . $column . '`';

Thanks

Presenter Issue

I have a presenter
trait StringPresenter {

public function getFullnameAttribute() {
    return ucfirst($this->fname) . ' ' . ucfirst($this->lname);
}

}

Controller
public function getData() {
$providers = Provider::select(['fullname', 'email','type','status','created_at'])->get();
return Datatables::of($providers)
->make();
}

Getting the debug error:
Unknown column 'fullname' in 'field list' .
But created_at trait is working fine.

How to add Print button?

This is my Js:

oTable = $('#projects').DataTable({
"processing": true,
"serverSide": true,
"ajax": "{{ URL::to('/projectsdata') }}",
"columns": [
{data: 'project_name', name: 'project_name'},
{data: 'project_location', name: 'project_location'},
{data: 'start_date', name: 'start_date'},
{data: 'end_date', name: 'end_date'},
{data: 'id', name: 'id'}
]
});

How can I add print Button in this?

EditColumn

I am trying to edit a date column so it only displays in d/m/y format.

$lineManagerReviews = Course::select()->where('lineManager','=',Auth::User()->id)->where('lineManagerApproved','=','unapproved');
return Datatables::of($lineManagerReviews)
->editColumn('startDate', function($data) {$data->startDate->format('d/m/y');})
->make(true);

This returns a null value for startDate can you tell me where I am going wrong please.

[Enhancement] DB::raw with filtering/search

I. Whenever I use DB::raw('CONCAT(field_name_1,field_name_2) AS something') in the "select", then the search/column filter does't seem to work. I see in the code you're doing something called a wrapColumn which I think is causing it to be escaped and therefore treated as a table column instead of a raw query.

Can you give some option where we can specify:

->setColumnSearchType('4','raw') OR setColumnSearchType([4,8],'raw') //and this will allow you to skip the wrapColumn clause for these columns

It might also be useful to have an additional option:

->setColumnSearchType('4','raw','having') //because sometimes when using aggregate functions like "MAX(score) as final_score", if you put them in the "where" condition, they won't work but if you put "HAVING final_score LIKE '%32%'" then it works

II. If pass "column_name as alias", doesn't seem to work but if i put "column_name AS alias", it works, you not allowing lowercase of "as"?

Problem when doing any kind of filtering

Hi yajra, first of all, your plugin is really amazing, but im having a problem with the last update that you did, in the version 4.0.11 i can make any kind of filter without problems, but i decided to update to 4.1.2.1 and when i try to filter something, laravel crashes and says :

FatalErrorException in Datatables.php line 439: Function name must be a string

But when i try to do the filter by one specific column it says:

ErrorException in Datatables.php line 473: Undefined variable: connection

Anyway thank you, meanwhile i'm using 4.0.11

Logging out the user randomly

After I installed the package and started to use it, it works perfectly. But the issue is every time I open a page that displays a table (with thousands of records) being handled by this plugin, it logs me out and redirects me to the login page. It happens randomly.

I am using Laravel 5 on a windows machine and a google chrome browser.

I am uploading my application to a production server to see if I get the same results. But for now this is my issue.

Column 'id' in where clause is ambiguous

Hy!

with leftJoin() function i have this error when i want to use search input.

Column 'id' in where clause is ambiguous (SQL: select count(*) as aggregate from (select '1' as row_count from articles left join users on users.id = articles.user_id where (id LIKE %a% or titre LIKE %a% or actif LIKE %a% or top LIKE %a% or nom LIKE %a%)) count_row_table)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.