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

stripHTML to remove any HTML wrappers on the data prior to cell data being set #168

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

PeterCassell92
Copy link

@PeterCassell92 PeterCassell92 commented Jun 8, 2020

I am using a platform called Verj.io to create my web application. Verj.io creates tables with excess HTML within the for each cell in the table. This is part of the way that Verj.io builds controls.

I found that when using datatables, some functionality (such as SearchPanes) would not work correctly because the HTML within the caused each entry to be unique so every entry had a frequency of 1. Also, the searchPane ended up misforming its own rows as the HTML would be escaped incorrectly.

I have added an option to allow people using a platform like Verj.io to treat the tables as if the data were directly in the element. I have allowed for this by using a stripHTML flag that can be defined in the ColumnDefs. This means that the HTML generated by Verj.io is not included in the cell data.

Peter Cassell added 2 commits June 8, 2020 19:52
…ld of a td so that platforms that generate excess HTML such as Verj.io can successfully integrate with DataTables. This functionality is set using columnDefs -> srcDataFromLastChild: true/false - default false
@DataTables
Copy link
Collaborator

Hi,

Thanks for the PR!

Could you show me an example of the markup created by Verj.io please? Does it have a wrapper span tag or something?

I'm not sure about pulling this in to be honest, as its the first request we've had for such a thing, but if it is popular enough, then we can certainly consider it.

@PeterCassell92 PeterCassell92 changed the title srcDataFromLastChild stripHTML to remove any HTML wrappers on the data prior to cell data being set Jun 9, 2020
@PeterCassell92
Copy link
Author

VerjioTD
VerjioTD2

The Verj.io table markup may come with 1 or 2 Div wrappers.

The problem that this causes with DataTables is twofold:-
1) searchPanes do not work correctly

datatablesBroken
verjSearchPaneHTML

2) it it inefficient to process so many extra characters when the data can be extracted more directly

So this is the problem I'm trying to solve. I think that my updated solution does this fairly succinctly but if there is another way to do this already in DataTables then let me know. Alternatively, this kind of functionality could be something that's built into the 'data' attribute rather than creating a new attribute like I have.

@DataTables
Copy link
Collaborator

Thanks for the screenshots. I agree - your solution to this is a nice one. My consider is that it is extra DOM checks (and thus slow) and extra code for one specific case. I also think that if you were to call row().invalidate('data') on your table, it would destroy the old HTML, thus possibly breaking some other interactions.

If it is a popular request, then I am happy to include it (or possibly we could make the DOM reading a plug-in system)

We'll look at what we can do with this with SearchPanes.

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