Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTables::make(collection) returns empty array into data property #1987

Closed
iam-mishgun opened this issue Feb 12, 2019 · 8 comments
Closed

Comments

@iam-mishgun
Copy link

For some reason, this method began to return an empty array, although there is data.
Previously, it was the of method. If you replace it - it does not work either.

Code snippet of problem

    $res = new Collection;
    foreach ($data as $company) {
      $company = (object)$company;
      if (gettype($company->properties) === 'array') {
        $company->properties = (object)$company->properties;
      }
      $res->push([
        'id' => $company->id,
        'company_name' => property_exists($company->properties, 'company_name') ? $company->properties->company_name : '',
        'company_phone' => property_exists($company->properties, 'company_phone') ? $company->properties->company_phone : '',
      ]);
    }

    // Make sure that there is data in the $res.
    // dd($res);

    return DataTables::make($res)
      ->addColumn('action', function ($company) {
        return '<a href="' . route('company_edit', $company['id']) . '" class="btn btn-xs btn-primary">Edit</a>';
      })->toJson();

System details

  • Operating System Ubuntu 17.10
  • PHP Version 7.1
  • Laravel Version 5.7
  • Laravel-Datatables Version 8.13.4
@yajra
Copy link
Owner

yajra commented Feb 15, 2019

Just an empty array and no error on response? The code looks fine.

@yajra yajra added the question label Feb 15, 2019
@thiagobrauer
Copy link

@GrimJacky same problem here, did you find a solution?

@Krato
Copy link

Krato commented Nov 10, 2021

Same problem filtering a collection.

$collection = Model::all();

//filter
$elements = $elements->filter(function ($appraisal) use ($column, $search) {
    if ($column == 'id') {
        return match (true) {
            ($search == 'vp') => $appraisal->video,
            str_contains('video', $search) => $appraisal->video,
            str_contains('extension', $search) => $appraisal->action->version > 1,
            default => str_contains($appraisal->id, $search),
        };
    }

    return false;
});


datatables()
    ->of($elements)...

Everything is working fine.

But for some reason when this line is fired str_contains('extension', $search) => $appraisal->action->version > 1,, the data return is an empty array.

But if I call dd($elements). is giving me 25 items. And also ajax is retuning:

draw: 9, recordsTotal: 25, recordsFiltered: 0, data: []

Don't know the reason but is not painting the table.

@github-actions
Copy link

github-actions bot commented Jun 5, 2023

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Jun 5, 2023
@sagar-celcius
Copy link

sagar-celcius commented Jun 7, 2023

Is this issue solved for anyone? I am facing the same issue. I am using Redis and feeding data as Array after applying pagination manually. I am geeting data for first page but not for other pages.

My issue has been solved with 'skipPaging()'.

@urshar
Copy link

urshar commented Aug 17, 2023

Is not clear why, but it solve my problem too

@heriher76
Copy link

Is this issue solved for anyone? I am facing the same issue. I am using Redis and feeding data as Array after applying pagination manually. I am geeting data for first page but not for other pages.

My issue has been solved with 'skipPaging()'.

this is awesome

@yajra
Copy link
Owner

yajra commented Jun 12, 2024

Since paging is being handled before being passed to dataTable, we need to use skipPaging to disable the internal paging function of the package. The package assumes that all data are loaded at once when using collection.

@yajra yajra closed this as completed Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants