コード例 #1
0
ファイル: DataTablePager.cs プロジェクト: simer27/PortalApi
        /// <summary>
        /// Apply the search terms to all the columns in the data set
        /// </summary>
        /// <returns>Data set as FormattedList</returns>
        public FormattedList Filter(bool sort = true)
        {
            var formattedList = new FormattedList();

            //  What are the columns in the data set
            formattedList.Import(this.properties.Select(x => x.Name + ",")
                                 .ToArray());

            //  Return same sEcho that was posted.  Prevents XSS attacks.
            formattedList.sEcho = this.echo;

            //  Return count of all records
            formattedList.iTotalRecords = this.queryable.Count();

            //  Filtered Data
            var records = this.queryable.Where(GenericSearchFilter());

            if (sort)
            {
                records = ApplySort(records);
            }


            //  What is filtered data set count now.  This is NOT the
            //  count of what is returned to client
            formattedList.iTotalDisplayRecords = (records.FirstOrDefault() == null) ? 0 : records.Count();

            //  Take a page
            var pagedRecords = records.Skip(this.displayStart)
                               .Take(this.displayLength);

            //  Convert to List of List<string>
            var aaData  = new List <List <string> >();
            var thisRec = new List <string>();

            pagedRecords.ToList()
            .ForEach(rec => aaData.Add(rec.PropertiesToList()));
            formattedList.aaData = aaData;

            return(formattedList);
        }