Skip to content

[CollectionProvider] Returned columns are empty #26

@timgws

Description

@timgws

I am using d765c9f

Here is my controller code:

class DatatableTestController extends Controller
{
    public function test() {
        $t = Datatable::make(new CollectionProvider(Categories::all()))
            ->column('id') // show the id column of the user model
            ->column('name', null, Searchable::NONE(), Orderable::NONE()) // also show the full name of the user, but do not allow searching or ordering of the column
            ->build();

        if ($t->shouldHandle()) {
            return $t->handleRequest();
        }

        return view('admin.test.categories', array(
            'datatable' => $t->view()
        ));
    }
}

admin/test/categories.blade.php has the following code:

    <h1>Testing Datatable 0.2.1</h1>

    {!!
        $datatable
            ->headers() // tell the table to render the header in the table
            ->columns('id', 'id') // show # in the header instead of 'id'
            ->columns('name', 'name') // show 'Full name' in the header instead of 'name'
            ->endpoint(route('admin.datatabletest'))
            // render just the table
            ->table()
    !!}
    {!!
        $datatable
            // now render the script
            ->script()
    !!}

The endpoint works perfectly 👍

The AJAX request that is sent contains the following request parameters:

sEcho:1
iColumns:2
sColumns:
iDisplayStart:0
iDisplayLength:10
mDataProp_0:id
mDataProp_1:name
sSearch:
bRegex:false
sSearch_0:
bRegex_0:false
bSearchable_0:true
sSearch_1:
bRegex_1:false
bSearchable_1:true
iSortCol_0:0
sSortDir_0:asc
iSortingCols:1
bSortable_0:true
bSortable_1:true

and the response is:

{
    "sEcho": "1",
    "iTotalRecords": 5,
    "iTotalDisplayRecords": 5,
    "aaData": [{
        "id": "",
        "name": ""
    }, {
        "id": "",
        "name": ""
    }, {
        "id": "",
        "name": ""
    }, {
        "id": "",
        "name": ""
    }, {
        "id": "",
        "name": ""
    }]
}

Note the empty id, and name for each column, even though running dd(Categories::all()) shows that there is infact data inside the Collection.

(Note that my register function inside DatatableServiceProvider has been edited to force VersionEngine to only use Datatable19Version (I could not find a way to nicely have ->view render with the datatable19.blade.php Datatable javascript, but that's a story for another feature request).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions