Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Only add 4 lines code into DatatableServiceProvider.php file it supports with Laravel 5 #239

Open
IftekherSunny opened this issue Feb 7, 2015 · 5 comments

Comments

@IftekherSunny
Copy link

Into boot function of DatatableServiceProvider I added this 4 lines code It works fine without any problem. If anyone want to change default setting by publishing the config and view by using Laravel 5 console command php artisan vendor:publish its also worked.

DatatableServiceProvider.php

    public function boot()
    {
        $this->publishes([
          __DIR__.'/../../views/' => base_path('resources/views/vendor/Chumper/views'),
          __DIR__.'/../../config/config.php' => config_path('packages/chumper_datatable.php'),
        ]);

        $this->loadViewsFrom(__DIR__.'/../../', 'Chumper');

        $this->mergeConfigFrom( __DIR__.'/../../config/config.php','chumper_datatable');
    }

config.php

 'table_view' => 'datatable::template', 
 'script_view' => 'datatable::javascript',

replacing this two lines in config.php file with

'table_view' => 'Chumper::views.template',
'script_view' => 'Chumper::views.javascript',

@Chumper brother please check this.

@saqueib
Copy link

saqueib commented Feb 13, 2015

I have tried your fix but I am getting below error

  Invalid number of options provided for the method "setOptions"
  in Table.php line 165
  at Table->setOptions(null) in Table.php line 87
  at Table->__construct() in Datatable.php line 39
  at Datatable->table() in Facade.php line 207
  at  Facade::__callStatic('table', array()) in UserController.php line 27

Here is my controller

 if(\Datatable::shouldHandle())
    {
        return \Datatable::collection(\App\User::all(array('id','name', 'email')))
            ->showColumns('id', 'name', 'email')
            ->searchColumns('name', 'email')
            ->orderColumns('id','name')
            ->make();
    }

    $table = \Datatable::table()
        ->addColumn('id','name', 'email')
        ->setUrl(route('user'))
        ->setOptions(array(
            'autoWidth' => true,
            'order' => [3, 'desc']
        ))
        ->noScript();

    return view('user.list', ['table', $table]);

I am using L 5.04, please help guys

@IftekherSunny
Copy link
Author

Goto vendor/chumper/datatable/src/views folder then open javascript.blade.php then replace this code with existing code. Better way you publish chumper view then replace this code with javascript.blade.php code. Both works fine. May be its happened Laravel new syntax for raw html output.

jQuery(document).ready(function(){
    // dynamic table
    oTable = jQuery('#{!! $id !!}').dataTable({

    @foreach ($options as $k => $o)
        {!! json_encode($k) !!}: @if(!is_array($o)) @if(preg_match("/function/", $o)) {!! $o !!} @else {!! json_encode($o) !!}, @endif
            @else
            [{
                @foreach ($o as $x => $r) 
                {!! json_encode($x) !!}: @if(is_array($r)) {!! json_encode($r) !!}, @elseif(preg_match("/function/", $r)) {!! $r !!}, @else {!! json_encode($r) !!} @endif
                @endforeach
            }],
            @endif

    @endforeach

    @foreach ($callbacks as $k => $o)
        {!! json_encode($k) !!}: {!! $o !!},
    @endforeach

    });
// custom values are available via $values array
});

@jayeshmagare
Copy link

Hi , i had the same problem with the set options method, updated the code javascript.blade.php , but still getting the same error , any update how to resolve it. Thanks.

@saqueib
Copy link

saqueib commented Feb 18, 2015

Hi Jayesh,
Here is how I fixed it.

=> I used @bart solution from here and mixed it with @IftekherSunny

and followed this instruction

   1. require "chumper/datatable": "l5-dev as 2.3" in your composer.json
   2. Add fork repo to your composer.json: "repositories": [ { "type": "vcs", "url": "https://github.com/bart/datatable.git" } ],
   3. Publish the config by using the new L5 console command php artisan vendor:publish

after that your composer.json will look like something this

 "require-dev": {
   "chumper/datatable": "l5-dev as 2.3"
 }
 "repositories": [ { "type": "vcs", "url": "https://github.com/bart/datatable.git" } ],

=> run composer update

=> now go to /vendor/chumper/datatable/src/Chumper/Datatable/DatatableServiceProvider.php

=> update your boot method to this

       public function boot()
       {
           $this->publishes([
               __DIR__.'/../../views/' => base_path('resources/views/vendor/Chumper/views'),
               __DIR__.'/../../config/config.php' => config_path('packages/chumper_datatable.php'),
         ]);

           $this->loadViewsFrom(__DIR__.'/../../', 'Chumper');

           $this->mergeConfigFrom( __DIR__.'/../../config/config.php','chumper_datatable');
       }

=> and finally change javascript.blade.php and view config

vendor/chumper/datatable/src/views/javascript.blade.php

<script type="text/javascript">
jQuery(document).ready(function(){
    // dynamic table
    oTable = jQuery('#{!! $id !!}').dataTable({

    @foreach ($options as $k => $o)
        {!! json_encode($k) !!}: @if(!is_array($o)) @if(preg_match("/function/", $o)) {!! $o !!} @else {!! json_encode($o) !!}, @endif
            @else
            [{
                @foreach ($o as $x => $r) 
                {!! json_encode($x) !!}: @if(is_array($r)) {!! json_encode($r) !!}, @elseif(preg_match("/function/", $r)) {!! $r !!}, @else {!! json_encode($r) !!} @endif
                @endforeach
            }],
            @endif

    @endforeach

    @foreach ($callbacks as $k => $o)
        {!! json_encode($k) !!}: {!! $o !!},
    @endforeach

    });
// custom values are available via $values array
});
</script>

and config vendor/chumper/datatable/src/config/config.php

     'table_view' => 'Chumper::views.template',
     'script_view' => 'Chumper::views.javascript',

=> after that you can run php artisan publish:vendor and thats it, it should work it

enjoy

@jayeshmagare
Copy link

Thanks @saqueib for step by step process, I also found the solution almost on the same lines which i put here : http://jayeshmagare.blogspot.com/2015/02/using-chumper-datatable-in-laravel-5.html . Hope this helps someone.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants