Skip to content

Conversation

@jiwom
Copy link
Contributor

@jiwom jiwom commented Oct 27, 2017

Use postCsv as button. This button is recommended for IE browsers since IE has URL length limit.

@jiwom
Copy link
Contributor Author

jiwom commented Oct 27, 2017

Example Snippet

public function html()
{
    return $this->builder()
        ->columns($this->getColumns())
        ->parameters([
                'buttons' => ['postCsv'],
        ]);
}

Take note of adding CSRF token

<meta name="csrf-token" content="{{ csrf_token() }}" />
<script type="text/javascript">
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

</script>

Take note of your Routing

$router->post('sample/export', SampleController::class . '@index');

@yajra
Copy link
Owner

yajra commented Oct 27, 2017

Can you please provide a complete snippet on how to use this including the routes?

@yajra
Copy link
Owner

yajra commented Oct 27, 2017

I think this csrf token will not work since you are using a native ajax call.

<meta name="csrf-token" content="{{ csrf_token() }}" />
<script type="text/javascript">
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

@jiwom
Copy link
Contributor Author

jiwom commented Oct 27, 2017

Thanks! Done! I have change the parameter token variable to $('meta[name="csrf-token"]').attr('content');

@yajra
Copy link
Owner

yajra commented Oct 27, 2017

Implementing Notes

  • Make sure you have meta header for the token on your template
<meta name="csrf-token" content="{{ csrf_token() }}" />
  • You need to add additional routes that will handle the export process but points to same method with the main dataTable get route.
Route::get('users', UsersController::class.'@index');
Route::post('users/export', UsersController::class.'@index');
  • Replce csv with postCsv on your buttons array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants