Skip to content

Conversation

@felorhik
Copy link
Contributor

I noticed when I was starting out with this package that the ajax source for datatable is always the root directory and there is no method to override this without editing the default view.

Made an update here that updates the view files allowing you to use $table->option('route', URL_HERE) to define the ajax source.

Not sure if this is the best way to do it since from what I see of this package so far it assumes that the ajax source is from the same route as the view source.

EDIT:

Noticed that the columns were based on the value of the array rather then the index, when the value is the label. This leads to errors when overriding table headers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!
Why did you change from label to name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When its going through the data it uses this to define what the index's of the data is, so when you use label it looks for lets say # for id instead of id. Changing it fixes it so that label is only used in the header and the data properly maps to the right columns.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, correct, makes sense now :)

Chumper added a commit that referenced this pull request Jan 28, 2016
Setup proper routing for table ajax
@Chumper Chumper merged commit bcf258a into OpenSkill:master Jan 28, 2016
@Chumper
Copy link
Contributor

Chumper commented Jan 28, 2016

Will merge it in but will remove the route option later when we introduce a separate option.

@timgws
Copy link
Member

timgws commented Feb 9, 2016

@Chumper what would you like to call the option?

I am thinking something along the lines of:

 $t = Datatable::make(new CollectionProvider(Categories::all())) ->column('id') // show the id column of the user model ->column('name', null, Searchable::NONE(), Orderable::NONE()) ->endpoint('admin.categories.datatable') ->build();

Where endpoint() would call the route() function to find out the final URL to send AJAX requests to.

@Chumper
Copy link
Contributor

Chumper commented Feb 9, 2016

IMO this should be an option on the view table object, as the backend does not care about any url, as it could be requested from any url.

So i would propose this in the view:

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

So it will be a member of https://github.com/OpenSkill/Datatable/blob/master/src/OpenSkill/Datatable/Views/DatatableView.php

@timgws
Copy link
Member

timgws commented Feb 10, 2016

OK, but there is only one small issue here. The $datatable object is called twice, it will mean that you might need to change calling ->endpoint() if you move the script() before the table().

I am thinking that calling ->endpoint() will store the variable in a private property, so it can be accessed by whatever needs to use it, but it just means the developer will need to ensure that ->endpoint() is called the first time that it is used when rendering the datatable for the first time.

This is why I think that it might be better to have it a little further up (however, doing that means editing OpenSkill\Datatable\Datatable & OpenSkill\Datatable\DatatableService and a whole bunch of other dependancies, which breaks the single responsibility principle).

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

Labels

None yet

3 participants