-
Notifications
You must be signed in to change notification settings - Fork 411
Any way to save element attributes that are assigned via element.someAttribute = "some value"? #95
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
Comments
@dkwin You mean like the data-* attribute? |
@Thrilleratplay Thanks for the reply, I was wondering if clusterizejs would actually store the variables as opposed to me having to store it in data-attributes (I'd have to refactor a ton of existing JS). I'd like to avoid refactoring existing JS if possible but rather just make a wrapper to mimic dom elements. |
Hello @dkwin |
Hi @NeXTs The issue I'm having is that some of the attributes assigned to DOM elements in my table are lost. There is legacy JS code that initializes the HTML table via Javascript, which sets attributes of DOM elements using the "=" operator (ie, someElement.someAttribute = "some Value"). These attributes are used for some dynamic functionality like onClicks, onHovers, etc. I want to avoid refactoring existing JS if possible so I'm wondering if there is a way for ClusterizeJS to preserve the attributes of the elements. The table is loaded in the following manner (alot of legacy code):
) Sorry for the confusion and I greatly appreciate any help |
That happens because after applying clusterize most of your rows were removed from DOM, that's why you can not access them by since you did not provide "rows" parameter to To be able make changes to rows in your case you have to change clusterize sources a bit.. after that (in theory) you will have access to parsed rows by clusterize instance (hence they will be in string format) by doing
iterate I understand, it may be not convenient for you to work with strings, but that's the only way I can see in this case. |
@NeXTs Thanks so much for your help. |
Is it possible to detach the rows from the tbody element and use that to pass in? For example
I tried doing that but it seems that I can get an error when Clusterize is trying to get the tag name of the first child of contentElem. Does the row data absolutely have to be an array of Strings? |
Yes it must be array of strings. You may be interested in this PR that allows to work with actual DON nodes instead of strings. But you are almost done with code you provided. The only thing left - to map your rows of DOM nodes to strings. You can easily do it by yourself. Hint how to do that |
Thanks, I actually used outerHTML before but I was hoping to somehow keep the attributes without doing too much gerry rigging. I think I'll go the route of the PR you just posted. Thanks again! |
Hi
I'm currently evaluating the plugin for a fairly large table.
Currently, I'm initializing the table as such (via existing html):
My table is initialized by html and some initial JS as well (some of which I cannot change). The JS also sets some attributes which are used to render the table.
IE
I'm wondering how to best persist the JS attributes when the elements are destroyed.
thanks for any info
The text was updated successfully, but these errors were encountered: