How to select ListView item by it's "ID" in the model

10 posts, 0 answers
  1. Ranjit
    Ranjit avatar
    12 posts
    Member since:
    Oct 2011

    Posted 23 Aug 2012 Link to this post

    After reading all documentation and the posts in the forums, It seems as noone has asked or posted anything regarding this functionality.

    I basically want to  "Select ListviewItem where AccountID = ID"

    How is this accomplished?


  2. Ranjit
    Ranjit avatar
    12 posts
    Member since:
    Oct 2011

    Posted 23 Aug 2012 Link to this post

    I figured out a method to do this, although it's not a very clean work around.

    here is the code in case anyone is interested... I am still curious as to whether this is possible without manually walking through the child collection.


    function SetSelectedAccountByID(id) {
            var listView = $("#Accounts-listview").data("kendoListView");
            var children = listView.element.children();
            var index = 0;
            for (var x = 0; x < children.length; x++) {
                if (listView.element.children()[x].id == id) {
                    index = x;
                };
            };
            
            // selects first list view item
            listView.select(children[index]);
        };
  3. Kendo UI is VS 2017 Ready
  4. Daniel
    Daniel avatar
    17 posts
    Member since:
    Jan 2014

    Posted 01 Sep 2014 Link to this post

    Why is an easy task as this one so difficult in Kendo?
    This has to be a built-in function!

    Regards,
    Daniel
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 01 Sep 2014 Link to this post

    Hello Daniel,


    By design the selection is performed over DOM elements. You could use the get() method of the dataSource to retrieve the exact dataItem via it's ID and then retrieve the DOM element via the uid attribute.

    Let me know if I could provide further assistance.

    Regards,
    Dimiter Madjarov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  6. Daniel
    Daniel avatar
    17 posts
    Member since:
    Jan 2014

    Posted 01 Sep 2014 in reply to Dimiter Madjarov Link to this post

    Hello Dimiter,

    I think this tasks are daily business for most developers. Why we are buying libraries such as Kendo? We don't want to use "Low Level API's" for basic tasks.

    One more point is, that Kendo is here and there a little bit inconsistent in its API.
    E.g. TreeView has a method .findByUid(). Why not ListView too!?

    Why don't have both (and other datasource) controls a method like .findById() ?


    Regards,
    Daniel
  7. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 01 Sep 2014 Link to this post

    Hello Daniel,


    All widgets that internally use a dataSource can access it and invoke it's getByUid method.
    E.g.
    var lv = $("#listview").data("kendoListView");
    lv.dataSource.getByUid(...);

    If you consider that we should add more methods to the ListView API, you could post this suggestion in our UserVoice portal. If the idea is popular among our users, we will consider to implement it in future releases.

    Regards,
    Dimiter Madjarov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  8. Daniel
    Daniel avatar
    17 posts
    Member since:
    Jan 2014

    Posted 01 Sep 2014 in reply to Dimiter Madjarov Link to this post

    You are correct, but I'm looking for the respective ListView-Item (for selecting)!

    Following returns the corresponding data item. I'm looking for the list-view item!
    lv.dataSource.getByUid(...);

    Now I do this:
    var listViewItem = lv.element.children("[data-uid='" + lv.dataSource.get(id).uid + "']");
    lv.select(listViewItem);

    I'm missing a method like in TreeView to do at least this:

    lv.select(lv.findByUid(lv.dataSource.get(id).uid));

    .findByUid doesn't exist on ListView, but on TreeView (this is inconsistent)

    I think this should be (built-in Kendo):

    lv.select(lv.findById(id));


    Regards
    Daniel

    PS: Be aware of using Uid and Id in my snippets
  9. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 01 Sep 2014 Link to this post

    Hi Daniel,


    Yes, this approach is correct for retrieving the corresponding DOM element via id and then selecting it.

    Thank you for the suggestion about the findByUid method. As stated previously, I would recommend to also post it in our User Voice portal.

    Regards,
    Dimiter Madjarov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  10. Peter
    Peter avatar
    44 posts
    Member since:
    Jan 2014

    Posted 15 Aug in reply to Dimiter Madjarov Link to this post

    The code required to select a ListView as provided here is just outrageously dumb. I'm sorry.

    Please don't ask us to vote for a feature that common sense already requires.

    Kendo should fix the API, as sensibly described in the posts here, of their own accord.

    It is your reputation, and the quality of your product. It is not our responsibility to beg you to fix it.

  11. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 16 Aug Link to this post

    Hello Peter,

    The reasoning behind this approach is that the ListView selection relies only on DOM elements. If any item should be retrieved via it's ID, this should be achieved through the DataSource API.

    Regards,
    Dimiter Madjarov
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
Back to Top
Kendo UI is VS 2017 Ready