Beispiel #1
0
        private GridRenderingData CreateRenderingData()
        {
            var renderingData = new GridRenderingData
            {
                TableHtmlAttributes = TableHtmlAttributes,
                DataKeyStore        = DataKeyStore,
                HtmlHelper          = new GridHtmlHelper <T>(ViewContext, DataKeyStore),
                UrlBuilder          = UrlBuilder,
                DataSource          = DataProcessor.ProcessedDataSource,
                Columns             = VisibleColumns.Cast <IGridColumn>(),
                GroupMembers        = DataProcessor.GroupDescriptors.Select(g => g.Member),
                Mode                   = CurrentItemMode,
                EditMode               = Editing.Mode,
                HasDetailView          = HasDetailView,
                Colspan                = Colspan - Columns.Count(column => column.Hidden),
                DetailViewTemplate     = MapDetailViewTemplate(HasDetailView ? DetailView.Template : null),
                NoRecordsTemplate      = FormatNoRecordsTemplate(),
                Localization           = Localization,
                ScrollingHeight        = Scrolling.Height,
                EditFormHtmlAttributes = Editing.FormHtmlAttributes,
                ShowFooter             = Footer && VisibleColumns.Any(c => c.FooterTemplate.HasValue() || c.ClientFooterTemplate.HasValue()),
                AggregateResults       = DataProcessor.AggregatesResults,
                Aggregates             = Aggregates.SelectMany(aggregate => aggregate.Aggregates),
                GroupsCount            = DataProcessor.GroupDescriptors.Count,
                ShowGroupFooter        = Aggregates.Any() && VisibleColumns.OfType <IGridBoundColumn>().Any(c => c.GroupFooterTemplate.HasValue()),
                PopUpContainer         = new HtmlFragment(),
#if MVC2 || MVC3
                CreateNewDataItem  = () => Editing.DefaultDataItem(),
                InsertRowPosition  = Editing.InsertRowPosition,
                EditTemplateName   = Editing.TemplateName,
                AdditionalViewData = Editing.AdditionalViewData,
                FormId             = ViewContext.FormContext.FormId,
#endif
                Callback = RowActionCallback
            };

            if (RowTemplate.HasValue())
            {
                renderingData.RowTemplate = (dataItem, container) => RowTemplate.Apply((T)dataItem, container);
            }

            return(renderingData);
        }
Beispiel #2
0
        public override void VerifySettings()
        {
            base.VerifySettings();

            this.ThrowIfClassIsPresent("k-grid-rtl", Exceptions.Rtl);

            if (!IsClientBinding && Scrollable.Enabled && Scrollable.Virtual)
            {
                throw new NotSupportedException(Exceptions.CannotUseVirtualScrollWithServerBinding);
            }

            if (AutoBind.HasValue)
            {
                if (!IsClientBinding || (IsClientBinding && DataSource.Data != null))
                {
                    throw new NotSupportedException(Exceptions.CannotSetAutoBindIfBoundDuringInitialization);
                }
            }

            if (Columns.Any(c => c.Locked) && !IsClientBinding)
            {
                throw new NotSupportedException(Exceptions.CannotUseLockedColumnsAndServerBinding);
            }

            if (IsClientBinding)
            {
                if (Columns.OfType <IGridTemplateColumn <T> >().Where(c => c.Template != null && string.IsNullOrEmpty(c.ClientTemplate)).Any())
                {
                    throw new NotSupportedException(Exceptions.CannotUseTemplatesInAjaxOrWebService);
                }

                if (DetailTemplate != null && DetailTemplate.HasValue() && string.IsNullOrEmpty(ClientDetailTemplateId))
                {
                    throw new NotSupportedException(Exceptions.CannotUseTemplatesInAjaxOrWebService);
                }

                if (Columns.Any(c => c.Locked))
                {
                    if (DetailTemplate != null && DetailTemplate.HasValue() || ClientDetailTemplateId.HasValue())
                    {
                        throw new NotSupportedException(Exceptions.CannotUseDetailTemplateAndLockedColumns);
                    }

                    if (ClientRowTemplate.HasValue() || RowTemplate != null && RowTemplate.HasValue())
                    {
                        throw new NotSupportedException(Exceptions.CannotUseRowTemplateAndLockedColumns);
                    }
                }

                if (Columns.OfType <IGridActionColumn>().Any(c => c.Commands.OfType <GridCustomActionCommand <T> >().Any(command => command.HasValue())))
                {
                    throw new NotSupportedException(Exceptions.CustomCommandRoutesWithAjaxBinding);
                }
            }

            if (!DataKeys.Any() && (Editable.Enabled || (Selectable.Enabled && !IsClientBinding)))
            {
                throw new NotSupportedException(Exceptions.DataKeysEmpty);
            }

            if (Editable.Enabled)
            {
                if (DataSource.Type != DataSourceType.Custom)
                {
                    if (HasCommandOfType <GridEditActionCommand>())
                    {
                        if (!DataSource.Transport.Update.HasValue())
                        {
                            throw new NotSupportedException(Exceptions.EditCommandRequiresUpdate);
                        }
                    }

                    if (HasCommandOfType <GridDestroyActionCommand>())
                    {
                        if (!DataSource.Transport.Destroy.HasValue() && Editable.Mode != GridEditMode.InCell)
                        {
                            throw new NotSupportedException(Exceptions.DeleteCommandRequiresDelete);
                        }
                    }

                    if (HasCommandOfType <GridToolBarCreateCommand <T> >())
                    {
                        if (!DataSource.Transport.Create.HasValue() && Editable.Mode != GridEditMode.InCell)
                        {
                            throw new NotSupportedException(Exceptions.InsertCommandRequiresInsert);
                        }
                    }
                }

                if (HasCommandOfType <GridToolBarSaveCommand <T> >())
                {
                    if (Editable.Mode != GridEditMode.InCell)
                    {
                        throw new NotSupportedException(Exceptions.BatchUpdatesRequireInCellMode);
                    }

                    if (DataSource.Type != DataSourceType.Custom)
                    {
                        if (!DataSource.Transport.Update.HasValue())
                        {
                            throw new NotSupportedException(Exceptions.BatchUpdatesRequireUpdate);
                        }
                    }
                }

                if (Editable.Mode == GridEditMode.InCell)
                {
                    if (!IsClientBinding)
                    {
                        throw new NotSupportedException(Exceptions.InCellModeNotSupportedInServerBinding);
                    }

                    if (ClientRowTemplate.HasValue() || ClientAltRowTemplate.HasValue() || RowTemplate.HasValue())
                    {
                        throw new NotSupportedException(Exceptions.InCellModeNotSupportedWithRowTemplate);
                    }
                }

                if (typeof(T) == typeof(System.Data.DataRowView) && Editable.Mode == GridEditMode.InLine &&
                    Columns.OfType <IGridBoundColumn>().Where(c => c.EditorTemplateName.HasValue()).Any())
                {
                    throw new NotSupportedException(Exceptions.DataTableInLineEditingWithCustomEditorTemplates);
                }

                if (typeof(T) == typeof(System.Data.DataRowView) && Editable.Mode == GridEditMode.PopUp &&
                    !Editable.TemplateName.HasValue())
                {
                    throw new NotSupportedException(Exceptions.DataTablePopUpTemplate);
                }
            }
        }
Beispiel #3
0
        public override void VerifySettings()
        {
            base.VerifySettings();

            this.ThrowIfClassIsPresent("t-grid-rtl", TextResource.Rtl);

            if (Ajax.Enabled && WebService.Enabled)
            {
                throw new NotSupportedException(TextResource.CannotUseAjaxAndWebServiceAtTheSameTime);
            }

            if (IsClientBinding)
            {
                if (Columns.OfType <IGridTemplateColumn <T> >().Where(c => c.Template != null && string.IsNullOrEmpty(c.ClientTemplate)).Any())
                {
                    throw new NotSupportedException(TextResource.CannotUseTemplatesInAjaxOrWebService);
                }

                if (DetailView != null && DetailView.Template.HasValue() && !DetailView.ClientTemplate.HasValue())
                {
                    throw new NotSupportedException(TextResource.CannotUseTemplatesInAjaxOrWebService);
                }
            }

            if (Paging.PageOnScroll)
            {
                if (!Paging.Enabled)
                {
                    throw new NotSupportedException(TextResource.PagingMustBeEnabledToUsePageOnScroll);
                }

                if (!Scrolling.Enabled)
                {
                    throw new NotSupportedException(TextResource.ScrollingMustBeEnabledToUsePageOnScroll);
                }

                if (!IsClientBinding)
                {
                    throw new NotSupportedException(TextResource.CannotUsePageOnScrollWithServerBinding);
                }
            }

            if (WebService.Enabled && string.IsNullOrEmpty(WebService.Select.Url))
            {
                throw new ArgumentException(TextResource.WebServiceUrlRequired);
            }

            if (!DataKeys.Any() && (Editing.Enabled || (Selection.Enabled && !IsClientBinding)))
            {
                throw new NotSupportedException(TextResource.DataKeysEmpty);
            }

            if (Editing.Enabled)
            {
                if (HasCommandOfType <GridEditActionCommand>())
                {
                    if (!CurrrentBinding.Update.HasValue())
                    {
                        throw new NotSupportedException(TextResource.EditCommandRequiresUpdate);
                    }
                }

                if (HasCommandOfType <GridDeleteActionCommand>())
                {
                    if (!CurrrentBinding.Delete.HasValue() && Editing.Mode != GridEditMode.InCell)
                    {
                        throw new NotSupportedException(TextResource.DeleteCommandRequiresDelete);
                    }
                }

                if (HasCommandOfType <GridToolBarInsertCommand <T> >())
                {
                    if (!CurrrentBinding.Insert.HasValue() && Editing.Mode != GridEditMode.InCell)
                    {
                        throw new NotSupportedException(TextResource.InsertCommandRequiresInsert);
                    }
                }

                if (HasCommandOfType <GridToolBarSubmitChangesCommand <T> >())
                {
                    if (Editing.Mode != GridEditMode.InCell)
                    {
                        throw new NotSupportedException(TextResource.BatchUpdatesRequireInCellMode);
                    }

                    if (!CurrrentBinding.Update.HasValue())
                    {
                        throw new NotSupportedException(TextResource.BatchUpdatesRequireUpdate);
                    }
                }

#if MVC2 || MVC3
                if (Editing.Mode == GridEditMode.InCell)
                {
                    if (!Ajax.Enabled && !WebService.Enabled)
                    {
                        throw new NotSupportedException(TextResource.InCellModeNotSupportedInServerBinding);
                    }

                    if (ClientRowTemplate.HasValue() || RowTemplate.HasValue())
                    {
                        throw new NotSupportedException(TextResource.InCellModeNotSupportedWithRowTemplate);
                    }
                }

                if (typeof(T) == typeof(System.Data.DataRowView) && Editing.Mode == GridEditMode.InLine &&
                    Columns.OfType <IGridBoundColumn>().Where(c => c.EditorTemplateName.HasValue()).Any())
                {
                    throw new NotSupportedException(TextResource.DataTableInLineEditingWithCustomEditorTemplates);
                }
#endif
            }
        }