javascriptsitecoresitecore-speak-ui

Sitecore SPEAK - set searchdatasource root programmatically


I have been playing with SPEAK dialogs lately. So far I like it, but have stumbled across an issue. I have passed with an itemID in the url parameters and I want to display the children of this item in a listcontrol.

My approach was to create a SearchDataSource and set the field "rootItemId" via javascript. This doesn't seem to work. Is there a way to access the SearchDataSource's rootItemId in the PageCode?


Solution

  • Another way I've been using lately is to use Anders Laub's JSON Datasource control here. http://laubplusco.net/creating-simple-sitecore-speak-json-datasource/.

    From the JavaScript PageCode you can then do a Ajax call and append in JSON result items to populate your listcontrol, where the listcontrols is bound to the JSON datasources Json property.

    $.ajax({
                    url: "/api/sitecore/RolePermissions/GetAllRoles",
                    type: "POST",
                    context: this,
                    success: function (data) {
                        var json = jQuery.parseJSON(data);
    
                        for (var i = 0; i < json.length; i++) {
                            var obj = json[i];
                            this.JsonDS.add(obj);
                        }
                    }
                });