コード例 #1
0
        internal void RenderStart(RenderContext context, Action <TagBuilder> onRender = null)
        {
            if (context.IsDialog && RunAt == RunMode.ServerUrl)
            {
                throw new XamlException("RunAt='ServerUrl' is not allowed in dialogs");
            }
            String cwTag = "collection-view";

            if (RunAt == RunMode.Server)
            {
                cwTag = "collection-view-server";
            }
            else if (RunAt == RunMode.ServerUrl)
            {
                cwTag = "collection-view-server-url";
            }
            _outer = new TagBuilder(cwTag, "cw", IsInGrid);
            onRender?.Invoke(_outer);
            if (Parent is Page)
            {
                _outer.AddCssClass("cw-absolute");
            }
            MergeAttributes(_outer, context);
            Bind itemsSource = GetBinding(nameof(ItemsSource));

            if (itemsSource != null)
            {
                _outer.MergeAttribute(":items-source", itemsSource.GetPath(context));
            }

            if (Sort != null)
            {
                _outer.MergeAttribute(":initial-sort", Sort.GetJsValue(context));
            }
            if (Filter != null)
            {
                _outer.MergeAttribute(":initial-filter", Filter.GetJsValue(context));
                _outer.MergeAttribute(":persistent-filter", Filter.GetPersistentValue(context));
                if (RunAt == RunMode.Client)
                {
                    if (String.IsNullOrEmpty(FilterDelegate))
                    {
                        throw new XamlException("To filter on the client, a FilterDelegate is required");
                    }
                    _outer.MergeAttribute(":filter-delegate", $"$delegate('{FilterDelegate}')");
                }
            }

            if (GroupBy != null)
            {
                _outer.MergeAttribute(":initial-group", GroupBy.GetJsValue(context));
            }

            if (PageSize != null)
            {
                _outer.MergeAttribute(":initial-page-size", PageSize.Value.ToString());
            }

            _outer.RenderStart(context);
            _inner = new TagBuilder("template");
            _inner.MergeAttribute("slot-scope", "Parent");
            _inner.RenderStart(context);
        }