asp.net-mvc - 当我尝试对 DataGrid 进行排序时 ..Data 消失了 ..但数据以 Json 响应的形式出现,并且未使用 Sortable() 在 UI 上显示
问题描述
单击 Sortable() 时数据正在绑定数据在 UI 上消失
@(Html.Kendo().Grid<Keys>(Model.baseKeysLocations).Name("SearchResultsGridLocation")
//.Sortable()
.Sortable(Sortable => Sortable.AllowUnsort(false))
.HtmlAttributes(new { style = "height: 450px" })
.Resizable(r => r.Columns(true))
.Reorderable(r => r.Columns(true))
.Scrollable(s => s.Virtual(true))
.Editable(e => e.Mode(GridEditMode.InCell))
.Pageable(p => p.Numeric(false).PreviousNext(false).Messages(m => m.Display("Total: {2}")))
.DataSource(ds => ds
.Ajax()
.AutoSync(true)
.Read(read => read.Action("Grid_KeyLocationRead", "Keys", new { @schdate = "", @drv = "" }))
.Model(m =>
{
m.Id(f => f.UniqueId);
m.Field(f => f.Schedule);
m.Field(f => f.TableId).Editable(false);
m.Field(f => f.FobId).Editable(false);
m.Field(f => f.RoomKey).Editable(false);
m.Field(f => f.Community).Editable(false);
m.Field(f => f.Lease).Editable(false);
m.Field(f => f.RoomKey).Editable(false);
m.Field(f => f.Driver).Editable(false);
m.Field(f => f.Status).Editable(false);
m.Field(f => f.FobId);
}
)
)
.Columns(columns =>
{
columns.Bound(f => f.UniqueId).Width("8rem").Hidden();
columns.Bound(f => f.TableId).Title("Id").Width("5rem").Hidden();
columns.Bound(f => f.RoomKey).Title("Key Location").Width("6rem");
columns.Bound(f => f.Community).Title("Community").Width("6rem");
columns.Bound(f => f.Lease).Title("Master").Width("6rem");
columns.Bound(f => f.Driver).Title("Driver").Width("6rem");
columns.Bound(client => client.Status).ClientTemplate("# if (Status == true) { #" + "IN" + "# } else {#" + "OUT" + "# } #").Title("Status").Width("8rem");
})
.Sortable()
)
</div>
*Data Was Binding When Sortable() was clicked data was Disappearing on UI*
*数据绑定 * 1:https ://i.stack.imgur.com/qRAmu.png 当按下排序功能时数据消失[2]:https ://i.stack.imgur.com/LVSld.png
- 试图对 DataGrid 进行排序 ..数据消失了 ..但数据作为 Json 响应出现并且它没有在 UI 上显示 Sortable() *
解决方案
function SearchLocationResults(search) {
$filter = new Array();
var leaseuid = null, complexuid = null;
if (search == true) {
if ($("#baseLocationViewModel_ComplexUId").data("kendoDropDownList").value() != '' && $("#baseLocationViewModel_ComplexUId").data("kendoDropDownList").value() != null && $("#baseLocationViewModel_ComplexUId").data("kendoDropDownList").value() != undefined) {
$filter.push({ field: "Driver", operator: "isequalto", value: $("#baseLocationViewModel_DriverUId").data("kendoDropDownList").value() });
complexuid = $("#baseLocationViewModel_ComplexUId").data("kendoDropDownList").value();
}
if ($("#baseLocationViewModel_MasterUId").data("kendoDropDownList").value() != '' && $("#baseLocationViewModel_MasterUId").data("kendoDropDownList").value() != null && $("#baseLocationViewModel_MasterUId").data("kendoDropDownList").value() != undefined) {
$filter.push({ field: "LeaseUId", operator: "isequalto", value: $("#baseLocationViewModel_MasterUId").data("kendoDropDownList").value() });
leaseuid = $("#baseLocationViewModel_MasterUId").data("kendoDropDownList").value();
}
}
$(".loadermodel").removeClass('d-none');
$.ajax({
url: '/Keys/Keys/Grid_KeyLocationRead',
type: "POST",
dataType: "json",
contentType: 'application/json; charset=utf-8',
async: false,
data: JSON.stringify({
request: $filter, schedule: $("#baseLocationViewModel_Schedule").val(), driver: $("#baseLocationViewModel_DriverUId").data("kendoDropDownList").value(), _complexUId: complexuid, _leaseUId: leaseuid
}),
cache: false,
success: function (result) {
$("#SearchResultsGridLocation").data('kendoGrid').dataSource.data([]);
$("#SearchResultsGridLocation").data('kendoGrid').dataSource.data(result);
$(".loadermodel").addClass('d-none');
},
error: function (err) {
$(".loadermodel").addClass('d-none');
}
});
}
推荐阅读
- mongodb - 更新 mongodb 数据库中的 json 文档
- android - 使用“工具”命名空间在 WebView 和 ViewPager 上预览数据
- html - 如何不在我的 HTML 模板中保留空格?
- ios - Mitmproxy 不适用于 snapchat 或 instagram
- typescript - 如何模拟 FacebookAuthProvider 等 Firebase 身份验证提供程序?
- sql-server - 导入外部表
- azure - Azure IoT Edge 模块:构建和推送 IoT Edge 解决方案时出错
- rust - 是否可以限制 Criterion 执行的迭代次数?
- javascript - JQuery 与 getElementId - 返回内容的差异
- python - 我们如何通过程序检查任何电子邮件 ID 是否可交付(真实存在或不存在)?