Skip to content
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

Bug Fix events on inner elements overriden by the existence of a custom render function #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

itay-grudev
Copy link

This addresses the following scenario:

I am adding existing (non-rendered to the DOM) TRs to DT with events
attached to their children.

I want a custom render function for providing filter and sort data, but
not display data. If there is a custom render function it overrides all
data including display data and overwrites the original cell content
(even if the data is unchanged) which results in the fact that events
of children inside the cell are lost.

This could be prevented if the render function can signal DT that it
doesn’t want to override the data and it wants to use the original
display data. Returning undefined is a good signal.

To address this issue, before overwriting the innerData of a cell using
the display data from the custom render function you can check whether
the data is null (undefined gets turned into null at this point).

And for all intents and purposes there is no point in overwriting the
cell content with null or undefined. Of course overwriting it with an
empty string ”” works correctly and would replace the display data (so
does null).

P.S. Changes are distributed under the terms of the MIT license, of course.

…om render function

This addresses the following scenario:

I am adding existing (non-rendered to the DOM) TRs to DT with events
attached to their children.

I want a custom render function for providing filter and sort data, but
not display data. If there is a custom render function it overrides all
data including display data and overwrites the original cell content
(even if the data is unchanged) which results in the fact that events
of children inside the cell are lost.

This could be prevented if the render function can signal DT that it
doesn’t want to override the data and it wants to use the original
display data. Returning undefined is a good signal.

To address this issue, before overwriting the innerData of a cell using
the display data from the custom render function you can check whether
the data is null (undefined gets turned into null at this point).

And for all intents and purposes there is no point in overwriting the
cell content with null or undefined. Of course overwriting it with an
empty string ”” works correctly and would replace the display data (so
does null).
@DataTables
Copy link
Collaborator

Thank you for this! Let me have a little think about this one if that's okay. I've always assumed that the display would return at least a string. I'm a little concerned that in this case someone might use cell().data() or row().data() as a setter and then think that DataTables should be updating their HTML as well.

@itay-grudev
Copy link
Author

This should only prevent setting the value to undefined. null and "" should both result in an empty cell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants