Esempio n. 1
0
        /// <summary>
        /// Handles the selection change event of the data list object to update the grid control.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        protected void OnListSelectionChanged(object sender, EventArgs e)
        {
            GridView grid = (GridView)control;

            grid.DataSource = list != null?list.GetData() : null;

            grid.DataBind();
        }
Esempio n. 2
0
        /// <summary>
        /// Handles selection update from the data list object by updating the list view selection
        /// </summary>
        private void OnListObjectSelectionChanged(object sender, EventArgs e)
        {
            ListView       listView = element as ListView;
            DataListObject listObj  = sender as DataListObject;

            if (PreventElementUpdate || listObj == null)
            {
                return;
            }

            PreventModelUpdate = true;

            // update selection model for list view as needed
            if (DataListObject.SelectionModeSingle.Equals(listObj.RowSelectionMode))
            {
                listView.SelectionMode = SelectionMode.Single;
            }
            else if (DataListObject.SelectionModeMultiple.Equals(listObj.RowSelectionMode) &&
                     listView.SelectionMode == SelectionMode.Single)
            {
                listView.SelectionMode = SelectionMode.Extended;
            }

            // clear selection
            if (listView.SelectionMode == SelectionMode.Single)
            {
                listView.SelectedItem = null;
            }
            else
            {
                listView.SelectedItems.Clear();
            }

            // set selected item(s) from the list object
            var listData = listObj.GetData();

            foreach (DataListObject.RowProxyObject r in listView.Items)
            {
                if (listData[r.Row].Selected)
                {
                    if (listView.SelectionMode == SelectionMode.Single)
                    {
                        listView.SelectedItem = r;
                        break;
                    }
                    else
                    {
                        listView.SelectedItems.Add(r);
                    }
                }
            }
            PreventModelUpdate = false;
        }
Esempio n. 3
0
        /// <summary>
        /// Binds the current GridView control to the specified data list object.
        /// Subscribes to listen for changes in the data list and update the grid accordingly.
        /// </summary>
        /// <param name="list">The data list object to bind to.</param>
        public virtual void BindTo(DataListObject list)
        {
            if (this.list != null)
            {
                this.list.CollectionChanged -= OnListChanged;
                this.list.SelectionChanged  -= OnListSelectionChanged;
            }
            this.list = list;
            if (list != null)
            {
                this.list.CollectionChanged += OnListChanged;
                this.list.SelectionChanged  += OnListSelectionChanged;
            }

            GridView grid = (GridView)control;

            grid.DataSource = list?.GetData();
            grid.DataBind();
        }
Esempio n. 4
0
        /// <summary>
        /// Updates selection in the specified list object for a details open/close event
        /// using the provided key property on the details view object.
        /// </summary>
        /// <param name="list">Data list object to update.</param>
        /// <param name="keyChildProp">The key property on the child details view.</param>
        /// <param name="e">Open/close event of the child details view.</param>
        /// <returns></returns>
        protected virtual bool UpdateListSelection(DataListObject list, DataProperty keyChildProp, ViewEvent e)
        {
            // Find key property in the list with the same name, as the key property in the child details object.
            var keyListProp = list?.Properties?.Where(p => p.IsKey && p.Name == keyChildProp?.Name)?.FirstOrDefault();

            if (keyListProp != null)
            {
                if (e.IsOpened())
                {
                    list.SelectedRows = list.GetData().Where(r => Equals(keyListProp.GetValue(ValueFormat.Internal, r),
                                                                         keyChildProp.InternalValue)).ToList();
                }
                else if (e.IsClosed())
                {
                    list.ClearSelectedRows();
                }
                return(true);
            }
            return(false);
        }
Esempio n. 5
0
        /// <inheritdoc/>
        public async override Task <object> ReadAsync(DataManagerRequest dm, string key = null)
        {
            DataListObject list = DataManager?.List;

            if (list == null)
            {
                return dm.RequiresCounts ? new DataResult()
                       {
                           Result = null, Count = 0
                       }
            }
            : null;

            IEnumerable <DataRow> data = list.GetData();

            if (dm.Where != null && dm.Where.Count > 0)
            {
                data = data.Where(r => Matches(r, "and", dm.Where));
            }
            if (dm.Search != null && dm.Search.Count > 0)
            {
                data = data.Where(r => Matches(r, "and", SearchToWhere(dm.Search)));
            }

            data = data.ToList(); // run the search before sorting and counting
            if (dm.Sorted != null && dm.Sorted.Count > 0)
            {
                var sortCrit = ToSortCriteria(dm.Sorted.Reverse <Sort>()); // multi-column sort comes in reverse order
                ((List <DataRow>)data).Sort(sortCrit);
            }

            int count = data.Count();

            if (dm.Skip != 0)
            {
                data = data.Skip(dm.Skip);
            }
            if (dm.Take != 0)
            {
                data = data.Take(dm.Take);
            }

            if (dm.Group != null)
            {
                IEnumerable groupedData = data;
                foreach (var group in dm.Group)
                {
                    groupedData = DataUtil.Group <DataRow>(groupedData, group, dm.Aggregates, 0, dm.GroupByFormatter);
                }
                return(dm.RequiresCounts ? new DataResult()
                {
                    Result = groupedData, Count = count
                } : (object)data);
            }
            var res = dm.RequiresCounts ? new DataResult()
            {
                Result = data, Count = count
            } : (object)data;

            return(await Task.FromResult(res));
        }