Ejemplo n.º 1
0
        public static GridDataModel GetData(IQueryable items, string columns, int page, int count, List<string> filter, string sort, string sortdir)
        {
            var columnsSplit = columns.Split(',').ToList();

            var gridData = new GridDataModel();

            //Sorting
            if (!string.IsNullOrWhiteSpace(sort))
            {
                if (string.IsNullOrWhiteSpace(sortdir))
                {
                    sortdir = "asc";
                }
                items = items.OrderBy(sort + " " + sortdir);
            }

            //Filtering
            if (filter == null)
            {
                filter = new List<string>();
            }
            var filteredData = items.Filter(columnsSplit, filter);

            gridData.TotalRows = filteredData.Count();
            gridData.PageCount = count;
            gridData.TotalPages = Convert.ToInt32(Math.Ceiling((double)gridData.TotalRows / (double)gridData.PageCount));

            if (page < 1)
            {
                page = 1;
            }
            if (page > gridData.TotalPages)
            {
                page = gridData.TotalPages;
            }
            gridData.CurrentPage = page;

            //Paging
            if (gridData.TotalRows > 0)
            {
                filteredData = filteredData.Skip(count * (page - 1)).Take(count).ToList();
            }

            foreach (var item in filteredData)
            {
                gridData.Data.Add(item);
            }

            return gridData;
        }
Ejemplo n.º 2
0
        public static GridDataModel GetData(IQueryable items, string columns, int page, int count, List <string> filter, string sort, string sortdir)
        {
            var columnsSplit = columns.Split(',').ToList();

            var gridData = new GridDataModel();

            //Sorting
            if (!string.IsNullOrWhiteSpace(sort))
            {
                if (string.IsNullOrWhiteSpace(sortdir))
                {
                    sortdir = "asc";
                }
                items = items.OrderBy(sort + " " + sortdir);
            }

            //Filtering
            if (filter == null)
            {
                filter = new List <string>();
            }
            var filteredData = items.Filter(columnsSplit, filter);

            gridData.TotalRows  = filteredData.Count();
            gridData.PageCount  = count;
            gridData.TotalPages = Convert.ToInt32(Math.Ceiling((double)gridData.TotalRows / (double)gridData.PageCount));

            if (page < 1)
            {
                page = 1;
            }
            if (page > gridData.TotalPages)
            {
                page = gridData.TotalPages;
            }
            gridData.CurrentPage = page;

            //Paging
            if (gridData.TotalRows > 0)
            {
                filteredData = filteredData.Skip(count * (page - 1)).Take(count).ToList();
            }

            foreach (var item in filteredData)
            {
                gridData.Data.Add(item);
            }

            return(gridData);
        }