Hi,
I have a dataset with millions of entries in it which I am displaying in the grid using the following code:
I would like to limit the amount of items returned (maxResults), say 1000 entries. I need this to work with server side filtering:
The problem with my code is that the .Take(maxResults) is performed before the filtering and sorting. This means that my grid does not display the correct results as expected, since the items are truncated before the filtering.
Is there a way of specifying a maximum number of returned entries in the ToDataSourceResult function? I need the filtering/sorting to be applied (server side) and then the returned results limited to <maxResults>, after the filtering and sorting is applied. I absolutely do not want millions of entries to be sent and then post-filtered, the filtering has to be done server side and then a limited number of results returned from the ToDataSourceResult function.
Thanks,
Michael
I have a dataset with millions of entries in it which I am displaying in the grid using the following code:
@(Html.Kendo().Grid<
LogEntryViewModel
>()
.Name("logsGrid")
.Columns(columns =>
{
columns.Bound(c => c.Id).Width(70);
columns.Bound(c => c.Date).Format("{0:dd/MM/yy H:mm:ss}").Width(140);
columns.Bound(c => c.IpAddress).Width(120);
columns.Bound(c => c.Message);
})
.Scrollable( )
.Sortable()
.Filterable()
.Pageable(pager => pager
.Input(true)
.Numeric(true)
.Info(true)
.Refresh(true))
.Resizable(resize => resize.Columns(true))
.HtmlAttributes(new {style = "height: 600px"})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(50)
.Read(read => read.Action("LogEntries_Read", "Home", new { maxResults = Model.MaxResults, }))
)
)
I would like to limit the amount of items returned (maxResults), say 1000 entries. I need this to work with server side filtering:
public ActionResult LogEntries_Read([DataSourceRequest] DataSourceRequest request, int maxResults)
{
try
{
using (var db = new SysLogContext())
{
IQueryable<
LogEntry
> logs = db.LogEntries.Take(maxResults);
try
{
var result = logs.ToDataSourceResult(request, logEntry => new LogEntryViewModel()
{
Id = logEntry.Id,
IpAddress = logEntry.IpAddress,
Date = logEntry.Date.DateTime,
Message = logEntry.Message,
});
return Json(result);
}
}
}
}
The problem with my code is that the .Take(maxResults) is performed before the filtering and sorting. This means that my grid does not display the correct results as expected, since the items are truncated before the filtering.
Is there a way of specifying a maximum number of returned entries in the ToDataSourceResult function? I need the filtering/sorting to be applied (server side) and then the returned results limited to <maxResults>, after the filtering and sorting is applied. I absolutely do not want millions of entries to be sent and then post-filtered, the filtering has to be done server side and then a limited number of results returned from the ToDataSourceResult function.
Thanks,
Michael