Код: Выделить всё
@(Html.Kendo().Grid()
.Name("FeedGrid")
.HtmlAttributes(new { @class = "FeedGrid" })
.Sortable(sortable => sortable
.AllowUnsort(true)
.SortMode(GridSortMode.MultipleColumn))
.Scrollable()
.ColumnMenu()
.Filterable()
.Reorderable(ro => ro.Columns(true))
.Resizable(rs => rs.Columns(true))
.Groupable()
.NoRecords("[i]---- No records found ----[/i][/b]")
.Columns(columns =>...)
.Events(events =>
{ events.ExcelExport("exportGridWithTemplatesContent");
events.ColumnShow("SaveGridState");
events.ColumnHide("SaveGridState");
events.ColumnReorder("SaveGridState");
events.ColumnResize("SaveGridState");
events.ColumnMenuInit("SortFilterDropdown");
events.DataBound("SaveGridState")};
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)));
Код: Выделить всё
var dataSource = new kendo.data.DataSource({
transport: {
read: function (options) {
$.ajax({
url: GetApiUrl('Api/GetGrid'),
contentType: "application/json;charset=utf-8",
data: JSON.stringify(DataSourceRequestViewModel(options, currentSearchXml)),
type: 'POST',
cache: false,
success: function (result) {
options.success(result);
},
error: function (result) {
options.error(result);
}
});
}
},
schema: {
data: "Data",
total: "Total"
}
});
setTimeout(function () {
$("#FeedGrid").data("kendoGrid").setDataSource(dataSource);
$("#FeedGrid").data("kendoGrid").dataSource.read();
}, 100);
var stateGrid = GetGridState("FeedGrid");
var grid = $("#FeedGrid").getKendoGrid();
stateGrid.toolbar = [{ template: kendo.template($('#FeedGrid').find(".k-grid-toolbar").html()) }];
if (!isNullOrEmpty(stateGrid)) {
grid.setOptions(stateGrid);
}
Я попробовал следующее решение: дождаться полной загрузки сетки, а затем использовать setoptions, но это загружает сетку дважды и не удобно для пользователя.< /p>
Проверенное решение:
Код: Выделить всё
function getFeedGridSettings(id) {
var isLoading = $('.k-loading-text').length;
if (isLoading) {
if (stateGrid == undefined) {
stateGrid = GetGridState(id);
stateGrid.toolbar = [{ template: kendo.template($('#' + id).find(".k-grid-toolbar").html()) }];
}
setTimeout(function () { getFeedGridSettings('FeedGrid'); }, 10000);
}
else {
if (!isNullOrEmpty(stateGrid)) {
var grid = $("#" + id).getKendoGrid();
grid.setOptions(stateGrid);
}
}
}
var dataSource = new kendo.data.DataSource({
transport: {
read: function (options) {
$.ajax({
url: GetApiUrl('Api/GetGrid'),
contentType: "application/json;charset=utf-8",
data: JSON.stringify(DataSourceRequestViewModel(options, searchXml)),
type: 'POST',
cache: false,
success: function (result) {
options.success(result);
},
error: function (result) {
options.error(result);
}
});
}
},
schema: {
data: "Data",
total: "Total"
}
});
setTimeout(function () { $("#FeedGrid").data("kendoGrid").setDataSource(dataSource) }, 100);
getFeedGridSettings('FeedGrid');
Подробнее здесь: https://stackoverflow.com/questions/784 ... id-state-u