private void DataBind(IDotvvmRequestContext context) { Children.Clear(); emptyDataContainer = null; head = null; var dataSourceBinding = GetDataSourceBinding(); var dataSource = DataSource; var sortCommand = SortChanged; sortCommand ??= typeof(ISortableGridViewDataSet).IsAssignableFrom((GetBinding(DataSourceProperty) as IStaticValueBinding)?.ResultType) ? (Action <string?>)SortChangedCommand : null; sortCommand ??= s => throw new DotvvmControlException(this, "Cannot sort when DataSource is null."); CreateHeaderRow(context, sortCommand); var index = 0; if (dataSource != null) { foreach (var item in GetIEnumerableFromDataSource() !) { // create row var placeholder = new DataItemContainer { DataItemIndex = index }; placeholder.SetDataContextTypeFromDataSource(dataSourceBinding); placeholder.DataContext = item; placeholder.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[" + index + "]"); placeholder.ID = index.ToString(); Children.Add(placeholder); CreateRowWithCells(context, placeholder); index++; } numberOfRows = index; } else { numberOfRows = 0; } // add empty item if (EmptyDataTemplate != null) { emptyDataContainer = new EmptyData(); emptyDataContainer.SetValue(EmptyData.VisibleProperty, GetValueRaw(VisibleProperty)); emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding); EmptyDataTemplate.BuildContent(context, emptyDataContainer); Children.Add(emptyDataContainer); } }
private DotvvmControl GetEmptyItem(IDotvvmRequestContext context) { var dataSourceBinding = GetDataSourceBinding(); emptyDataContainer = new EmptyData(); emptyDataContainer.SetValue(EmptyData.RenderWrapperTagProperty, GetValueRaw(RenderWrapperTagProperty)); emptyDataContainer.SetValue(EmptyData.WrapperTagNameProperty, GetValueRaw(WrapperTagNameProperty)); emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding); EmptyDataTemplate.BuildContent(context, emptyDataContainer); return(emptyDataContainer); }
/// <summary> /// Performs the data-binding and builds the controls inside the <see cref="Repeater"/>. /// </summary> private void DataBind(IDotvvmRequestContext context) { Children.Clear(); emptyDataContainer = null; var dataSourceBinding = GetDataSourceBinding(); var index = 0; var dataSource = DataSource; if (dataSource != null) { var itemBinding = GetItemBinding(); var bindingService = context.Configuration.ServiceLocator.GetService <BindingCompilationService>(); foreach (var item in GetIEnumerableFromDataSource()) { var placeholder = new DataItemContainer { DataItemIndex = index }; ItemTemplate.BuildContent(context, placeholder); placeholder.SetBinding(DataContextProperty, ValueBindingExpression.CreateBinding( bindingService, j => item, itemBinding.KnockoutExpression.AssignParameters(p => p == JavascriptTranslator.CurrentIndexParameter ? new CodeParameterAssignment(index.ToString(), OperatorPrecedence.Max) : default(CodeParameterAssignment)))); placeholder.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[" + index + "]"); placeholder.ID = index.ToString(); Children.Add(placeholder); index++; } numberOfRows = index; } else { numberOfRows = 0; } // add empty item if (EmptyDataTemplate != null) { emptyDataContainer = new EmptyData(); emptyDataContainer.SetValue(EmptyData.RenderWrapperTagProperty, GetValueRaw(RenderWrapperTagProperty)); emptyDataContainer.SetValue(EmptyData.WrapperTagNameProperty, GetValueRaw(WrapperTagNameProperty)); emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding); EmptyDataTemplate.BuildContent(context, emptyDataContainer); Children.Add(emptyDataContainer); } }
/// <summary> /// Performs the data-binding and builds the controls inside the <see cref="Repeater"/>. /// </summary> private void DataBind(IDotvvmRequestContext context) { Children.Clear(); emptyDataContainer = null; var dataSourceBinding = GetDataSourceBinding(); var index = 0; var dataSource = DataSource; if (dataSource != null) { var items = GetIEnumerableFromDataSource(dataSource).Cast <object>().ToArray(); var javascriptDataSourceExpression = dataSourceBinding.GetKnockoutBindingExpression(); foreach (var item in items) { var placeholder = new DataItemContainer { DataItemIndex = index }; ItemTemplate.BuildContent(context, placeholder); placeholder.SetBinding(DataContextProperty, GetItemBinding((IList)items, javascriptDataSourceExpression, index)); placeholder.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), index)); placeholder.ID = index.ToString(); Children.Add(placeholder); index++; } numberOfRows = index; } else { numberOfRows = 0; } // add empty item if (EmptyDataTemplate != null) { emptyDataContainer = new EmptyData(); emptyDataContainer.SetValue(EmptyData.RenderWrapperTagProperty, GetValueRaw(RenderWrapperTagProperty)); emptyDataContainer.SetValue(EmptyData.WrapperTagNameProperty, GetValueRaw(WrapperTagNameProperty)); emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding); EmptyDataTemplate.BuildContent(context, emptyDataContainer); Children.Add(emptyDataContainer); } }
private void DataBind(IDotvvmRequestContext context) { Children.Clear(); emptyDataContainer = null; head = null; var dataSourceBinding = GetDataSourceBinding(); var dataSource = DataSource; var sortCommand = dataSource is ISortableGridViewDataSet sortableSet && sortableSet.SortingOptions is ISortingOptions sortOptions ? expr => { if (sortOptions.SortExpression == expr) { sortOptions.SortDescending ^= true; } else { sortOptions.SortExpression = expr; sortOptions.SortDescending = false; } (sortableSet as IPageableGridViewDataSet)?.GoToFirstPage(); } : SortChanged; // WORKAROUND: DataSource is null => don't throw exception if (sortCommand == null && dataSource == null) { sortCommand = s => { throw new DotvvmControlException(this, "Cannot sort when DataSource is null."); }; } CreateHeaderRow(context, sortCommand); var index = 0; if (dataSource != null) { var itemBinding = GetItemBinding(); foreach (var item in GetIEnumerableFromDataSource()) { // create row var placeholder = new DataItemContainer { DataItemIndex = index }; placeholder.SetDataContextTypeFromDataSource(dataSourceBinding); placeholder.DataContext = item; placeholder.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[" + index + "]"); placeholder.ID = index.ToString(); Children.Add(placeholder); CreateRowWithCells(context, placeholder); index++; } numberOfRows = index; } else { numberOfRows = 0; } // add empty item if (EmptyDataTemplate != null) { emptyDataContainer = new EmptyData(); emptyDataContainer.SetValue(EmptyData.VisibleProperty, GetValueRaw(VisibleProperty)); emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding); EmptyDataTemplate.BuildContent(context, emptyDataContainer); Children.Add(emptyDataContainer); } }
private void DataBind(IDotvvmRequestContext context) { Children.Clear(); emptyDataContainer = null; head = null; var dataSourceBinding = GetDataSourceBinding(); var dataSource = DataSource; Action <string> sortCommand = null; if (dataSource is IGridViewDataSet) { sortCommand = ((IGridViewDataSet)dataSource).SetSortExpression; } else { sortCommand = SortChanged; } // WORKAROUND: DataSource is null => don't throw exception if (sortCommand == null && dataSource == null) { sortCommand = s => { throw new Exception("can't sort null data source"); }; } CreateHeaderRow(context, sortCommand); var index = 0; if (dataSource != null) { // create header row var items = GetIEnumerableFromDataSource(dataSource); var javascriptDataSourceExpression = dataSourceBinding.GetKnockoutBindingExpression(); foreach (var item in items) { // create row var placeholder = new DataItemContainer { DataItemIndex = index }; placeholder.SetBinding(DataContextProperty, GetItemBinding((IList)items, javascriptDataSourceExpression, index)); placeholder.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), index)); placeholder.ID = "i" + index; CreateRow(context, placeholder); Children.Add(placeholder); index++; } numberOfRows = index; } else { numberOfRows = 0; } // add empty item if (EmptyDataTemplate != null) { emptyDataContainer = new EmptyData(); emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding); EmptyDataTemplate.BuildContent(context, emptyDataContainer); Children.Add(emptyDataContainer); } }
private void DataBind(IDotvvmRequestContext context) { Children.Clear(); emptyDataContainer = null; head = null; var dataSourceBinding = GetDataSourceBinding(); var dataSource = DataSource; if (dataSource is IRefreshableGridViewDataSet refreshableDataSet) { CallGridViewDataSetRefreshRequest(refreshableDataSet); } var sortCommand = dataSource is ISortableGridViewDataSet sortableGridViewDataSet ? sortableGridViewDataSet.SetSortExpression : SortChanged; // WORKAROUND: DataSource is null => don't throw exception if (sortCommand == null && dataSource == null) { sortCommand = s => { throw new DotvvmControlException(this, "Cannot sort when DataSource is null."); }; } CreateHeaderRow(context, sortCommand); var index = 0; if (dataSource != null) { var itemBinding = GetItemBinding(); var bindingService = context.Configuration.ServiceLocator.GetService <BindingCompilationService>(); foreach (var item in GetIEnumerableFromDataSource()) { // create row var placeholder = new DataItemContainer { DataItemIndex = index }; placeholder.SetBinding(DataContextProperty, ValueBindingExpression.CreateBinding( bindingService, j => item, itemBinding.KnockoutExpression.AssignParameters(p => p == JavascriptTranslator.CurrentIndexParameter ? new CodeParameterAssignment(index.ToString(), OperatorPrecedence.Max) : default(CodeParameterAssignment)))); placeholder.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[" + index + "]"); placeholder.ID = index.ToString(); Children.Add(placeholder); CreateRowWithCells(context, placeholder); index++; } numberOfRows = index; } else { numberOfRows = 0; } // add empty item if (EmptyDataTemplate != null) { emptyDataContainer = new EmptyData(); emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding); EmptyDataTemplate.BuildContent(context, emptyDataContainer); Children.Add(emptyDataContainer); } }