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

Get Data In Client Events

6 Answers 156 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Velma
Top achievements
Rank 1
Velma asked on 19 Jul 2011, 11:55 PM
(I am using version 2011.1.519.40; I will try to get the Q2 release downloaded if that will allow me to get what I need. I see the new LoadOnDemand functionality in the documentation, which would definitely help us.)

I have the TreeList loading fine from a datatable.

I need to do just a few things which I expected were straightforward...

(1) When an item is selected, I need to get two of the bound data items (one of which displays and one of which doesn't--the one that doesn't is the "DataKeyNames" item). I then need to do server side actions depending on what I determine from those two data items.
         (a) I can't find any way to retrieve those data items (astonishingly to me).
         (b) There doesn't appear to be a server side event for Selected. So, what do you recommend for hitting a server method from a client-side event in this context?

Can you (I mean, Telerik support) or anyone provide a code snippet which would accomplish this?

(2) When an item is double-clicked, I need to get "DataKeyNames" item, and depending on what I determine from it, possibly expand the node.
         (a) I can't find any way to retrieve this data item (astonishingly to me).
         (b) There doesn't appear to be a server side event for Double-Click. So, what do you recommend for hitting a server method from a client-side event in this context?

Can you/anyone provide a code snippet which would accomplish this?

(3) I don't want to add/edit/delete data directly from the list. Can I add or delete programatically, rather than reloading the whole datatable and requerying? Is there a sample showing something like this?

Actually, I'm willing/just as happy to do any of this server-side, client-side or server-side, whichever...

Thanks.

6 Answers, 1 is accepted

Sort by
0
Velma
Top achievements
Rank 1
answered on 20 Jul 2011, 07:13 PM
I got the Q2 release now.
0
Velma
Top achievements
Rank 1
answered on 20 Jul 2011, 09:48 PM
With the Q2 release,
I can now get the data values of the cells in the selected/clicked row in client-side events:

var item = eventArgs.get_item();
var treelist = item.get_owner();
var country = treelist.getCellByColumnUniqueName(item, "CountryName").innerText;

But I still can't get the key values by anything I've tried.
var key = item.get_dataKeyValue("DataID");
returns null
etc.
I tried adding a hidden column, but nothing I tried would make a hidden column ("style=display:none" is not supported, width=0 doesn't actually hide it completely...).

0
Velma
Top achievements
Rank 1
answered on 26 Jul 2011, 05:21 PM
Since nobody has suggested anything, I continue poking away at this.

I managed to get the keys on the server side:

if (RadTreeList1.SelectedItems.Count == 0) return;
TreeListDataItem current = RadTreeList1.SelectedItems[0];
string dataKeyValue = current.GetDataKeyValue("DataID").ToString();
string parentKeyValue = current.ParentItem.GetDataKeyValue("DataID").ToString();

However, the corresponding methods on the client side return null:

 var treelist = $find("<%= RadTreeList1.ClientID %>");
 var items = treelist.get_selectedItems();
var item = items[0];
key = item.get_dataKeyValue("DataID"); -- RETURNS NULL
var parent = item.get_parentItem();
key = parent.get_dataKeyValue("DataID"); -- RETURNS NULL

Anybody know how to get this to work?
0
Velma
Top achievements
Rank 1
answered on 26 Jul 2011, 06:13 PM
Alright, I hope this may help someone else who may otherwise be banging their head against the wall also.

There is another attribute of the RadTreeList call "ClientDataKeyNames". I have no idea why.

So now I have: DataKeyNames="DataID" ParentDataKeyNames="ParentID" ClientDataKeyNames="DataID"

And then:

var treelist = $find("<%= RadTreeList1.ClientID %>");
 var items = treelist.get_selectedItems();
var item = items[0];
key = item.get_dataKeyValue("DataID"); -- RETURNS CORRECT VALUE!
var parent = item.get_parentItem();
key = parent.get_dataKeyValue("DataID"); -- RETURNS CORRECT VALUE!

Telerik, perhaps you could extract the useful code samples from this thread and add them to the help. Because none of this is documented.
0
Steve Napurano
Top achievements
Rank 1
answered on 18 Sep 2011, 01:15 AM
i know! This treelist is brutal on dicumentation
All I want to do is get the selected key and child values on server side

How did you iterate thru the list and get selected values?

0
Tsvetina
Telerik team
answered on 19 Sep 2011, 09:09 AM
Hi Velma and Steve ,

First, on the ClientDataKeyNames. This property follows the logic of our other databound controls (like RadGrid). The DataKeyNames property is used for creating such collection on the server. It would not be good for performance to create it on the client by default when it is not needed in many cases. Therefore, a separate property is used to mark which values need to be stored on the client too.

The need of using the ClientDataKeyNames property is outlined in the get_dataKeyValue() property description, too.
The treelist documentation is still being built and parts are still missing but main client-side specifics are already described in the Client-side programming section.

As for server-side iteration over the selected items, Steve, have you tried iterating the SelectedItems collection of the RadTreeList control and then the ChildItems collection of each selected item to access all needed values:
protected void RadTreeList1_PreRender(object sender, EventArgs e)
{
    foreach (TreeListDataItem item in RadTreeList1.SelectedItems)
    {
        string keyValue = item.GetDataKeyValue("EmployeeID").ToString();
        Response.Write(keyValue);
        foreach (TreeListDataItem childItem in item.ChildItems)
        {
            string childKeyValue = childItem.GetDataKeyValue("EmployeeID").ToString();
            Response.Write(childKeyValue);
        }
    }
}


Best wishes,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
Tags
TreeList
Asked by
Velma
Top achievements
Rank 1
Answers by
Velma
Top achievements
Rank 1
Steve Napurano
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or