Persisting the Selected Items Client-side

4 posts, 0 answers
  1. Gábor
    Gábor avatar
    1 posts
    Member since:
    May 2012

    Posted 21 May 2012 Link to this post

    Hello,

    I'd like to persist the selected Items on client side. I've found an article that describes the solution for RadGrids: http://www.telerik.com/help/aspnet-ajax/grid-persist-selected-rows-client-sorting-paging-grouping-filtering.html .

    I tried to apply this solution for RadTreeList. I've replaced the OnRowCreated, OnRowSelected, OnRowDeselected, OnGridCreated event handlers with OnItemCreated, OnItemSelected, OnItemDeselected, OnTreeListCreated event handlers. When the grid is created the OnItemCreated even handler fires and the connected javascript is invoked. When this script invokes the args.get_item().set_selected(true); method I receive a javascript error message the tells me that the this._owner._selectedItems is null. After debugging the script I found that the _owner is null. I thought when this event handler is fired all properties of the item has been set. It seems that I was wrong.

    Could you tell me how I can change the selection of a item when the page is loaded or the node is expanded or the control is paginated?

  2. Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 24 May 2012 Link to this post

    Hi Gábor,

    I ported the sample code for you:
    function TreeListItemSelected(sender, args)
    {
        var id = args.get_item().get_dataKeyValue("ID");
        if (!selected[id])
        {
            selected[id] = true;
        }
    }
    function TreeListItemDeselected(sender, args)
    {
        var id = args.get_item().get_dataKeyValue("ID");
        if (selected[id])
        {
            selected[id] = null;
        }
    }
    function TreeListItemCreated(sender, args)
    {
        var id = args.get_item().get_dataKeyValue("ID");
        if (selected[id])
        {
            args.get_item().set_selected(true);
        }
    }
    function TreeListCreated(sender, args)
    {
        var headerCheckBox = $get("RadTreeList1").getElementsByTagName("input")[0];
        var pageSize = $telerik.findControl(sender.get_element(), "PageSizeComboBox").get_value();
        if (headerCheckBox)
        {
            headerCheckBox.checked = sender.get_selectedItems().length == pageSize;
        }
    }

    Good luck

    Daniel
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tim
    Tim avatar
    1 posts
    Member since:
    May 2013

    Posted 07 May 2013 Link to this post

    Just to note, I get the same 'this._owner._selectedItems' is null or not an object error on RadTreeList even when using the 'ported' code posted here. It seems to occur after having selected items across two pages. If I then move page again, e.g. back to the first page, this error occurs. If I ignore the error it appear to be working as expected however, just that it throws this error during TreeListItemCreated. Noting this is with version 2012.2.912.40. It occurs within RadTreeListScripts.js
  5. Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 10 May 2013 Link to this post

    Hello Tim,

    RadTreeList should persist the selected indices out of the box. Could you please try the attached demo to verify this?

    Kind regards,
    Daniel
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top