Я новичок в MVC и абсолютно новичок в кендо.
У меня есть сетка Kendo на странице MVC, загрузка которой занимает слишком много времени, после небольшого исследования я обнаружил, что виновной является следующая строка
return Json(result.ToDataSourceResult(request));
Каковы альтернативы? в DatasourceResult? Как я могу ускорить процесс?
Мой метод выглядит так:
public ActionResult GetExportJobDetails([DataSourceRequest] DataSourceRequest request, string hubId)
{
string jobStratNumber = "";
if (!string.IsNullOrEmpty(hubId))
{
jobStratNumber = getJobsStartNumber(hubId);
TempData["hubId"] = hubId;
}
var result = helperServiceLayer.getExportJobsNotDeclared(jobStratNumber);
//var x = result.ToDataSourceResult(request);
string jsonResponse = JsonConvert.SerializeObject(result);
var returnResult = new JsonResult
{
Data = JsonConvert.DeserializeObject(jsonResponse)
};
// Builds but the grid does not show any data.
//return Content(jsonResponse, "application/json");
//return Content(returnResult, "application/json");
//return returnResult;
// Works and grid shows data but it is extremely slow.
return Json(result.ToDataSourceResult(request));
}
Мой код сетки (CSHTML) выглядит так:
@(Html.Kendo().Grid<DT.SInt.Models.JobDetails>()
.Name("Grid")
//.Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Columns(columns =>
{
@*columns.Template(@<text></text>).ClientTemplate("<a href='' onclick=\"save('#=JobNumber#','#=ConsignmentNumber#')\">Send</a>").Width(50).Locked(true).Lockable(false);*@
columns.Template(@<text></text>).ClientTemplate("<div class='sendClass'><a href='' >Send</a></div>").Width(38);
columns.Bound(j => j.JobNumber).Width(78)
.Filterable(ftb => ftb.Cell(cell => cell.Operator("Contains").SuggestionOperator(FilterType.Contains).ShowOperators(false).InputWidth(100)))
.HeaderHtmlAttributes(new { style = "font-weight:bold;" });
columns.Bound(j => j.ConsignmentNumber).Title("Consignment").Width(84).Filterable(false).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
columns.Bound(j => j.ShipperCode).Width(60).Filterable(false).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
columns.Bound(j => j.ShipperName).Width(220).Filterable(false).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
//columns.Bound(j => j.ConsigneeName).Width(165).Lockable(false);
columns.Bound(j => j.HomeModel.SAddressCode).Title("SCode").Width(70).Filterable(false).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
columns.Bound(j => j.JobType).Width(50).Filterable(false).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
columns.Bound(j => j.FlightNumber).Title("Flight No.").Width(60).Filterable(false).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
columns.Bound(j => j.FlightDate).Width(80).Filterable(false).HeaderHtmlAttributes(new { style = "center;font-weight:bold;" }).HtmlAttributes(new { @class = "flight-date" });
//columns.Bound(p => p.HomeModel.DeclarationType).Width(140).ClientTemplate("#= HomeModel.DeclarationType #").Width(50).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
columns.Template(@<text></text>).ClientTemplate("<div class='amendUcrClass'><a href='' >Shippers UCR</a></div>").Width(70);
//columns.Bound(j => j.HomeModel.GoodDescription).Width(115);
//columns.Bound(j => j.FlightDate).Width(120).EditorTemplateName("dateTimeEditor")
// .ClientTemplate("#= FlightDate ? kendo.toString(kendo.parseDate(FlightDate), 'dd/MM/yyyy') : '' #");
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(25)
.ServerOperation(false)
.Batch(true)
.Model(m =>
{
m.Id(p => p.ConsignmentNumber);
//m.Field(p => p.HomeModel.DeclarationType).DefaultValue(1);
m.Field(p => p.JobNumber).Editable(false) ;
m.Field(p => p.ConsignmentNumber).Editable(false);
m.Field(p => p.ShipperCode).Editable(false);
m.Field(p => p.ShipperName).Editable(false);
m.Field(p => p.HomeModel.SAddressCode).Editable(false);
//m.Field(p => p.ConsigneeName).Editable(false);
m.Field(p => p.JobType).Editable(false);
m.Field(p => p.FlightNumber).Editable(false);
m.Field(p => p.FlightDate).Editable(false);
m.Field(p => p.HomeModel.GoodDescription).Editable(false);
})
.Read(r => r.Action("GetExportJobDetails", "Home").Data("getAdditionalParam"))
.Events(events => events.Sync("sync_handler_ShipmentGridNotDeclared"))
)
.Events(events => events.DataBound("onDataBound_NotClearedGrid"))
//.AutoBind(true)
.Sortable(sortable => sortable
.AllowUnsort(true)
.SortMode(GridSortMode.MultipleColumn)
.ShowIndexes(true))
//.Filterable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
//.ColumnMenu()
//.Groupable()
.HtmlAttributes(new { @class = "small", style = "height:68.00em;" })
.Pageable(p => p.Refresh(true).ButtonCount(10).PageSizes(new int[] { 25, 50, 100, 200 }))
.Scrollable()
.NoRecords(x => x.Template("<div class='empty-grid'></div>"))
//.Resizable(r => r.Columns(true))
//.Reorderable(r => r.Columns(true))
)