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

Help finding the IDs of elements selected ... #45

Open
inglesuniversal opened this issue Oct 29, 2021 · 3 comments
Open

Help finding the IDs of elements selected ... #45

inglesuniversal opened this issue Oct 29, 2021 · 3 comments

Comments

@inglesuniversal
Copy link

Hello, my code looks as follows and even though I am able to select the items properly, I am trying to create an array of the IDs of the items selected, but all I get is a blank {} curly brackets.

Here is the code I'm using:

<div id="row_P6CtxjdhyiEPOPxilMHf" class="files-item ui-selectable ui-selected">
</div>

var ids = $('div#showFiles.file-list.ui-selected').map(function() {
return $(this).attr('id');
});

alert(ids.length);
alert(ids[0]);

I get zero and then undefined in the output function

Best regards

@Mobius1
Copy link
Owner

Mobius1 commented Oct 29, 2021

Use: getSelectedNodes()

const selectedElements = instance.getSelectedNodes();
const ids = selectedElements.map(el => el.id);

@inglesuniversal
Copy link
Author

It worked as expected... Awesome and thanks for your help.

now, is there a way to have a similar function but grab only the ids of the elements which are being de-selected?

something like...

const selectedElements = instance.getUnSelectedNodes(); // getUnSelectedNodes(); ---> ?
const ids = selectedElements.map(el => el.id);

@Mobius1
Copy link
Owner

Mobius1 commented Apr 27, 2022

You can iterate over the items and check their properties:

item.selected    // Is item selected
item.selecting   // Is item flagged for selection
item.deselecting // Is item flagged for de-selection

So for getting items being de-selected just check if the deselecting property is true and return the node's id if it is:

const ids = instance.items.map(item => item.deselecting ? item.node.id : false).filter(item => !!item);

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

No branches or pull requests

2 participants