This is a migrated thread and some comments may be shown as answers.

Persisting the Selected Items Client-side

3 Answers 82 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Gábor
Top achievements
Rank 1
Gábor asked on 21 May 2012, 02:52 PM

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?

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 24 May 2012, 04:03 PM
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.
0
Tim
Top achievements
Rank 1
answered on 07 May 2013, 02:16 PM
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
0
Daniel
Telerik team
answered on 10 May 2013, 04:58 PM
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.
Tags
TreeList
Asked by
Gábor
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Tim
Top achievements
Rank 1
Share this question
or