New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add clickable row option for grid actions #15859
Changes from 1 commit
ffcef55
994c477
fd38963
8a476f2
ac30917
b7ecc51
File filter...
Jump to…
Make row action code more readable, and manage confirm message on row…
… click
- Loading branch information
@@ -35,29 +35,54 @@ export default class LinkRowActionExtension { | ||
* @param {Grid} grid | ||
*/ | ||
extend(grid) { | ||
$('tr', grid.getContainer()).each(function () { | ||
this.initRowLinks(grid); | ||
this.initConfirmableActions(grid); | ||
} | ||
|
||
/** | ||
* Extend grid | ||
* | ||
* @param {Grid} grid | ||
*/ | ||
initConfirmableActions(grid) { | ||
grid.getContainer().on('click', '.js-link-row-action', (event) => { | ||
const confirmMessage = $(event.currentTarget).data('confirm-message'); | ||
|
||
if (confirmMessage.length && !confirm(confirmMessage)) { | ||
event.preventDefault(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Add a click event on rows that matches the first link action (if present) | ||
* | ||
* @param {Grid} grid | ||
*/ | ||
initRowLinks(grid) { | ||
$('tr', grid.getContainer()).each(function initEachRow() { | ||
const $parentRow = $(this); | ||
|
||
$('.js-link-row-action[data-clickable-row=1]:first', $parentRow).each(function () { | ||
const $rowLink = $(this); | ||
$('.js-link-row-action[data-clickable-row=1]:first', $parentRow).each(function propagateFirstLinkAction() { | ||
const $rowAction = $(this); | ||
const $parentCell = $rowAction.closest('td'); | ||
|
||
const $parentCell = $rowLink.closest('td'); | ||
/* | ||
* Only search for cells with non clickable contents to avoid conflicts with | ||
* previous cell behaviour (action, toggle, ...) | ||
*/ | ||
const clickableCells = $('td.data-type, td.identifier-type, td.badge-type', $parentRow) | ||
.not($parentCell) | ||
; | ||
|
||
clickableCells.addClass('cursor-pointer').click(() => { | ||
This conversation was marked as resolved
by PierreRambaud
jolelievre
Author
Contributor
|
||
document.location = $rowLink.attr('href'); | ||
const confirmMessage = $rowAction.data('confirm-message'); | ||
|
||
if (!confirmMessage.length || confirm(confirmMessage)) { | ||
document.location = $rowAction.attr('href'); | ||
} | ||
}); | ||
}); | ||
}); | ||
This conversation was marked as resolved
by sarjon
|
||
|
||
grid.getContainer().on('click', '.js-link-row-action', (event) => { | ||
const confirmMessage = $(event.currentTarget).data('confirm-message'); | ||
|
||
if (confirmMessage.length && !confirm(confirmMessage)) { | ||
event.preventDefault(); | ||
} | ||
}); | ||
} | ||
} |
What if you click on a checkbox, or a link in the cell?