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

Modify hasChildren property value of HierarchicalDataSource's item

1 Answer 77 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Francesc
Top achievements
Rank 1
Francesc asked on 04 Jun 2013, 12:57 PM
I'm creating an App with a filesystem. The filesystem contains folders wichs may contain folder or files. Before requesting the transport.read() we don't know if a folder contains subitems. We assume that a folder will contain subitems, so we set "hasChildren" property to true.

How we set "hasChildren" to false once the request returns no subitems, to make the expanding tree dissappear ?

fileSystem: {
                        items: new kendo.data.HierarchicalDataSource({
                            transport: {
                                read: function(options) {
                                    var url = (options.data && options.data.src) ? options.data.src : null;
                                    
                                    var request = PncServices.getFilesytem(url, {});
                                    
                                    request.done(function(data, textStatus, jqXHR) {
                                        var items = [];
                                        $.each(data, function(key, value) {
                                            
                                            var uri = URI(value);
                                            var parts = uri.toString().split("/");
                                            var index = (parts[parts.length-1] === "") ? parts.length-2 : parts.length-1;
                                            var isFolder = (index === parts.length-1);
                                            var label = parts[index];
                                            
                                            var item = {
                                                src: value,
                                                label: label,
                                                hasChildren: !isFolder
                                            };
                                            
                                            if(items.length <= 0) {
                                                //TODO: Set hasChildren to false
                                                //fileSystem.items.get(url).set("hasChildren", false);

                                            }
                                            
                                            items.push(item);
                                        });
                                        
                                        options.success(items);
                                    });
                                    
                                    request.fail(function(jqXHR, textStatus, errorThrown) {
                                        options.error(errorThrown);
                                    });
                                },
                            },
                            
                            schema: {
                                model: {
                                    id: "src",
                                    hasChildren: "hasChildren"
                                }
                            }
                        })   

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 06 Jun 2013, 10:45 AM
Hi,

The expand icon will automatically be removed when no children are returned from the server in the latest service pack release. I created a small jsBin example that demonstrates this functionality.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Francesc
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or