'Datatable returns empty data when used with a filter

I'm using yajra-datatable along with an API, this is my datasource:

public function datasource()
{
    $search = request()->post('search');
    $start = request()->post('start');
    $length = request()->post('length');

    $response = $this->packages::searchByDrugName([
        'page' => $start / $length,
        'name' => $search['value']
    ]);

    $this->setOffset($response['to']);
    $this->setTotalRecords($response['total']);

    return $response['data'];
}

I'm calling an external API service through an SDK, and when the DataTable loads I can see all the rows correctly, this is the $response value (check on pastebin).

When I type something in the search bar, eg "idro", I get this $response value(check on pastebin).

The problem's that after the second call, so when I valorized the search bar with "idro", I doesn't get any rows displayed even if the response has returned data. This is the response returned:

enter image description here

I initially though that was a problem of the API, but I tried to add this before searchByDrugName: $search['value'] = 'idro';. So I have simulated the search type of "idro" without typing anything in the search box, and the Datatable has returned the expected rows.

I guess there is a conflict somewhere that prevent the DataTable to return the data array when the search box is filled, specifically when the method setOffset and setTotalRecords are used.

Could you kindly look into this?

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source