Sitecore SPEAK - set searchdatasource root programmatically

327 views Asked by At

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?

2

There are 2 answers

0
Komainu85 On BEST ANSWER

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);
                    }
                }
            });
0
CosX On

I managed to do this with query. In pageCode:

public class SelectTitle : PageCodeBase
    {
        //Fetches DataSource as rendering
        public Rendering DataSource { get; set; }

        public override void Initialize()
        {
            var articleid = WebUtil.GetQueryString("article");

            if (!String.IsNullOrEmpty(articleid))
            {
                //Set the query.
                this.DataSource.Parameters["query"] =
                    String.Format("fast:/some/path/*[@@id = '{0}']/Elements/*[@@templateid = '{1}']", articleid, '{guid}');
            }
        }
    }