Example #1
0
        public void Pageable_Builder_CreatesGridPager()
        {
            htmlGrid.Grid.Pager = null;

            htmlGrid.Pageable(pager => { });

            IGridPager <GridModel> expected = new GridPager <GridModel>(htmlGrid.Grid);
            IGridPager <GridModel> actual   = htmlGrid.Grid.Pager;

            Assert.AreEqual(expected.FirstDisplayPage, actual.FirstDisplayPage);
            Assert.AreEqual(expected.PartialViewName, actual.PartialViewName);
            Assert.AreEqual(expected.PagesToDisplay, actual.PagesToDisplay);
            Assert.AreEqual(expected.ProcessorType, actual.ProcessorType);
            Assert.AreEqual(expected.InitialPage, actual.InitialPage);
            Assert.AreEqual(expected.CurrentPage, actual.CurrentPage);
            Assert.AreEqual(expected.RowsPerPage, actual.RowsPerPage);
            Assert.AreEqual(expected.TotalPages, actual.TotalPages);
            Assert.AreEqual(expected.TotalRows, actual.TotalRows);
            Assert.AreSame(expected.Grid, actual.Grid);
        }
Example #2
0
        public async Task UpdateGrid()
        {
            try
            {
                ItemsDTO <T> response;
                if (_dataService == null)
                {
                    string urlParameters = ((GridPager)_pager).GetLink();
                    if (Url.Contains("?"))
                    {
                        urlParameters = urlParameters.Replace("?", "&");
                    }
                    HttpClient httpClient = new HttpClient();
                    response = await httpClient.GetJsonAsync <ItemsDTO <T> >(Url + urlParameters);
                }
                else
                {
                    response = _dataService((QueryDictionary <StringValues>)_query);
                }
                if (response != null && response.Items != null && response.Pager != null)
                {
                    Items        = response.Items;
                    EnablePaging = response.Pager.EnablePaging;
                    _pager       = new GridPager(_query, response.Pager.CurrentPage);
                    ((GridPager)_pager).PageSize   = response.Pager.PageSize;
                    ((GridPager)_pager).ItemsCount = response.Pager.ItemsCount;

                    if (response.Totals != null)
                    {
                        if (response.Totals.Sum != null)
                        {
                            foreach (var keyValue in response.Totals.Sum)
                            {
                                var column = (GridColumnBase <T>)Columns.SingleOrDefault(r => r.Name != null && r.Name.Equals(keyValue.Key));
                                if (column != null && column.IsSumEnabled)
                                {
                                    column.SumString = keyValue.Value;
                                }
                            }
                        }

                        if (response.Totals.Average != null)
                        {
                            foreach (var keyValue in response.Totals.Average)
                            {
                                var column = (GridColumnBase <T>)Columns.SingleOrDefault(r => r.Name != null && r.Name.Equals(keyValue.Key));
                                if (column != null && column.IsAverageEnabled)
                                {
                                    column.AverageString = keyValue.Value;
                                }
                            }
                        }

                        if (response.Totals.Max != null)
                        {
                            foreach (var keyValue in response.Totals.Max)
                            {
                                var column = (GridColumnBase <T>)Columns.SingleOrDefault(r => r.Name != null && r.Name.Equals(keyValue.Key));
                                if (column != null && column.IsMaxEnabled)
                                {
                                    column.MaxString = keyValue.Value;
                                }
                            }
                        }

                        if (response.Totals.Min != null)
                        {
                            foreach (var keyValue in response.Totals.Min)
                            {
                                var column = (GridColumnBase <T>)Columns.SingleOrDefault(r => r.Name != null && r.Name.Equals(keyValue.Key));
                                if (column != null && column.IsMinEnabled)
                                {
                                    column.MinString = keyValue.Value;
                                }
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Response is null");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
 /// <summary>
 ///     Extract query string parameter name from default grid pager (if using)
 /// </summary>
 private string GetPagerQueryParameterName(IGridPager pager)
 {
     var defaultPager = pager as GridPager;
     if (defaultPager == null)
         return string.Empty;
     return defaultPager.ParameterName;
 }
Example #4
0
 public PagerGridItemsProcessor(IGridPager pager)
 {
     _pager = pager;
 }