Open jhargis opened 9 years ago
I think the "formatters" paramter should be changed or adjusted in general so that you can affect the cell element directy and e.g. inject DOM elements with already bound events. For example:
formatters: {
'foobar': function(column, row, cell) {
var link = $('<a>').on('click', function() { alert('foobar') });
link.appendTo(cell);
}
}
I see no reason why you would like to return only the plain HTML and bind the events in a separate method.
Delegation doesn't work because bootgrid stop click propagation with event.stopPropagation() (so the click event never reach beyond tbody).
From the docs: "Use the loaded.rs.jquery.bootgrid event to bind custom events to your controls rendered by a formatter."
So, your last example (the one that works) it's the intended way.
You can use jquery.off() to remove old bindings.
I'm struggling to understand why I can't get event delegation working with a dynamic bootgrid element.
if i set a breakpoint just prior to the jquery.on, the selector is found. The child target does not exist yet, and at this point, the delegation fails to find the child target(
span.report-search-add-btn
) after the child is dynamically populated, post grid load.It does not work after grid initialize/initialized.
It DOES work if I place the event binding inside loaded.rs.jquery.bootgrid
But this creates new bindings every time data loads into the grid, so potentially tons of unnecessary binding.
Any idea what is going on here?