singlequote / Laravel-datatables

This repo contains a Datatable that can render a filterable and sortable table. It aims to be very lightweight and easy to use. It has support for retrieving data asynchronously, pagination and recursive searching in relations.
https://singlequote.github.io/Laravel-datatables/
MIT License
18 stars 6 forks source link

Feature Request: Option to add custom attributes #26

Closed macgadger closed 3 years ago

macgadger commented 3 years ago

Hi,

Feature Request, Please add function to fields so that user can add custom data attributes to buttons etc like:

<button data-href="route/id/edit" data-title="Edit this">Edit</button>

i tried to do it myself but unable to get model id from route to attribute value. I also find that there is no function to enable/disable and modify autoreload datatables.

Bug: When you dont add route or anything to button, when clicked button redirecting to undefined route. which i fixed.

Thanks.

wimurk commented 3 years ago

Hi @macgadger,

this is already possible by using the data method. For example on a button

Button::make('my-column')->data(["href" => "id"]) // <button data-href="1">Edit</button>

The docs are incomplete for data attributes. I will edit the issue for incomplete docs en examples.

wimurk commented 3 years ago

Below the list of modifications

macgadger commented 3 years ago

Hi @macgadger,

this is already possible by using the data method. For example on a button

Button::make('my-column')->data(["href" => "id"]) // <button data-href="1">Edit</button>

The docs are incomplete for data attributes. I will edit the issue for incomplete docs en examples.

Great! Work like charm. :)

while working on data attributes , i found that i can not pass custom strings or route to attributes like:

Button::make('action')->class('btn btn-outline-info btn-sm modal-link')->icon("fa fa-plus")->data([ 'href' => 'id', 'url' => route('users.edit','id'), 'placement' => 'top' ]),

with code above i am getting error in console:

data-placement="undefined"in html code VM7590:8 Uncaught SyntaxError: Missing } in template expression in console

Thanks in advance.

wimurk commented 3 years ago

Hi @macgadger,

thats correct, the data method doens't support custom data objects other then column values. Can you create a new issue with this enhancement ?