Laravel-datatables: Export All Records

Created on 16 Nov 2015  Â·  9Comments  Â·  Source: yajra/laravel-datatables

Any easy way to have all records (no pagination) when exporting records? I have 10000 records that I want paginated but I don't want in the drop down (Show X records) to have All or 10000, but when they export to Excel, CSV, or Print I would like all records.

If there isn't an option available for this I might try and implement one.

Most helpful comment

Doesn't work for me too
Using datatables 1.10.12 and laravel-datatables 6.0

public function query()
{
$envios = Envio::select();
return $this->applyScopes($envios);
}

public function ajax()
{
return $this->datatables
->eloquent($this->query())
->make(true);
}

All 9 comments

Just send or hard code the length parameter to -1. See this method as ref:

    protected function getAjaxResponseData()
    {
        $this->datatables->getRequest()->merge(['length' => -1]); // will show all results

        $response = $this->ajax();
        $data     = $response->getData(true);

        return $data['data'];
    }

Strange, that's how my getAjaxResponseData is exactly, but it still only shows records based on what I choose in the Show area. I'll see if I can see why. Thanks!

It appears that the request only gets partly modified.

[server] => Symfony\\Component\\HttpFoundation\\ServerBag Object 
   (
   [parameters:protected] => Array ([QUERY_STRING],[REQUEST_URI]
   )

contain the wrong length still (as they are strings and not key/value I am assuming), and the print, excel, and csv exports still only show 10 or 20 records according to what is in the drop down.

This is using datatables as a service, perhaps that makes a difference in this case.

It seems like there's bug. I just confirmed it thru the demo. Thanks for taking time to check this.

No probs im still learning but if I come up with an appropriate fix I will
PR.
On 2015-11-17 5:04 PM, "Arjay Angeles" [email protected] wrote:

It seems like there's bug. I just confirmed it thru the demo. Thanks for
taking time to check this.

—
Reply to this email directly or view it on GitHub
https://github.com/yajra/laravel-datatables/issues/258#issuecomment-157564203
.

I found the culprit. When using the service approach, we should not use of method because it recreates the Request instance. The proper approach would be:

public function ajax()
{
    return $this->datatables
        ->eloquent($this->query()) // when using eloquent
        ->queryBuilder($this->query()) // when using query builder
        ->collection($this->query()) // when using collection
        ->make(true);
}

Thank you Yajra!

It doesn't work with me :/
I tried ->eloquent($this->query()) ..

Doesn't work for me too
Using datatables 1.10.12 and laravel-datatables 6.0

public function query()
{
$envios = Envio::select();
return $this->applyScopes($envios);
}

public function ajax()
{
return $this->datatables
->eloquent($this->query())
->make(true);
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

macnux picture macnux  Â·  3Comments

ahmadbadpey picture ahmadbadpey  Â·  3Comments

techguydev picture techguydev  Â·  3Comments

hohuuhau picture hohuuhau  Â·  3Comments

kamrava picture kamrava  Â·  3Comments