public DatatablesRepsonse GetResponse <TSource>(IQueryable <TSource> query, DataTablesRequest param)
        {
            var totalRecords = query.Count(); //Execute this query

            var modelProperties = ModelProperties <TSource> .Properties;

            query = DataTablesFiltering.ApplyFilterAndSort(query, modelProperties, param);
            var totalDisplayRecords = query.Count(); //Execute this query

            var skipped = query.Skip(param.Start);
            var data    = (param.Length <= 0 ? skipped : skipped.Take(param.Length)).ToArray(); //Execute this query

            return(new DatatablesRepsonse
            {
                recordsTotal = totalRecords,
                recordsFiltered = totalDisplayRecords,
                draw = param.Draw,
                data = data.Cast <object>().ToArray(),
            });
        }
예제 #2
0
        public DataTablesResponseData GetDataTablesResponse <TSource>(IQueryable <TSource> data)
        {
            var totalRecords = data.Count(); // annoying this, as it causes an extra evaluation..

            var filters = new DataTablesFiltering();

            var outputProperties = DataTablesTypeInfo <TSource> .Properties;

            var filteredData        = filters.ApplyFiltersAndSort(this, data, outputProperties);
            var totalDisplayRecords = filteredData.Count();

            var skipped = filteredData.Skip(this.iDisplayStart);
            var page    = (this.iDisplayLength <= 0 ? skipped : skipped.Take(this.iDisplayLength)).ToArray();

            var result = new DataTablesResponseData()
            {
                iTotalRecords        = totalRecords,
                iTotalDisplayRecords = totalDisplayRecords,
                sEcho  = this.sEcho,
                aaData = page.Cast <object>().ToArray(),
            };

            return(result);
        }