I don't like the "edit"-button at the end of each entity on the INDEX-Page (EasyAdmin 3 / symfony 5) and I would like to have the table-row clickable and it shall send me directly to the EDIT-page.
I guess the solution must be using Javascript, so I started:
PHP-file
class PersonCrudController extends AbstractCrudController {
[...]
public function configureFields(string $pageName): iterable {
[...]
yield TextField::new('fullName', 'Name')->onlyOnIndex()->setCssClass('js-row-action');
[...]
}
[...]
}
javascript-file
// call functions once page is loaded
document.addEventListener("DOMContentLoaded", function() {
makeTableRowClickable();
});
function makeTableRowClickable() {
let elements = document.getElementsByClassName('js-row-action');
for (let i = 0; i < elements.length; i++) {
let td = elements[i];
let tr = td.parentNode;
tr.addEventListener("click", function (e) {
alert('click the row, Jack!');
});
}
}
open questions
- How do I generate the URL of the EDIT-page?
- How can I set a data attribute with the URL into any (hidden) field so that I can use it in the javascript?
Any ideas? Many thanks!