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

Select specific node in Listview at runtime #1554

Closed
Pitanium opened this issue Jun 5, 2020 · 2 comments
Closed

Select specific node in Listview at runtime #1554

Pitanium opened this issue Jun 5, 2020 · 2 comments

Comments

@Pitanium
Copy link

Pitanium commented Jun 5, 2020

Hello,

I have been using the framework for some time now. Very good work!
I cant find any function, that can do this. I hope I haven't missed anything.

I use the (selectable) Listview control for a site with permission settings. I had the problem that I can't select certain nodes at runtime (i.e. select the node if the permission is already granted).

I extendet the listview.js (source/components/listview/listview.js) with the following method behind line 403:

selectSpecificOne: function(attributeName, attributeValue) {
        this.element.find('li[data-' + attributeName + '="' + attributeValue + '"]' + ' > .checkbox input').prop("checked", true);
        this.element.trigger('change');
   };

Parameters:
attributeName: The method searches the element for the given data attribute (i.e. data-id =>
lv.selectSpecificOne('id', '123);

attributeValue: The value for the data attribute.

If I have a set of ids to select, I can use this function to select them all:

var ids = '123,456,789';
var array = ids.split(',');

for (let i = 0; i < array.length; i++) {
    var lv = Metro.getPlugin('#lv', 'listview');
    lv.selectSpecificOne('id', array[i]);
}

The found elements get selected.

Perhaps it is possible to integrate this or a similar proposal.

olton added a commit that referenced this issue Jun 5, 2020
@olton olton added this to the 4.3.8 milestone Jun 5, 2020
@olton
Copy link
Owner

olton commented Jun 5, 2020

Hi Robin! Thanks for this purpose. I added method selectByAttribute in 4.3.8. You can test it from branch 4.3.8 or dev from cdn. For using:

<div>
    <button class="button" onclick="selectSpecified()">Select specified</button>
    <button class="button" onclick="selectSpecified(false)">Deselect specified</button>
</div>


<ul data-role="list-view" id="list-view" data-selectable="true">
    <li id="l1">...</li>
    <li id="l2">...</li>
    <li id="l3">...</li>
    <li id="l4">...</li>
    <li id="l5">...</li>
</ul>
function selectSpecified(select){
    var val = ["l2", "l5", "l7", "l8"], attr = "id";
    var lv = Metro.getPlugin("#listview", "listview");
    $.each(val, function(){
        lv.selectByAttribute(attr, this, select);
    })
}

@Pitanium
Copy link
Author

Pitanium commented Jun 5, 2020

Hey Sergey,

thank you very much!

@olton olton closed this as completed Jun 21, 2020
olton added a commit that referenced this issue Oct 28, 2023
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