我有一个大约有 80 列的剑道网格。基于一些逻辑我隐藏/显示列。前 20 列是静态的,其余 60 列取决于员 worker 数(例如:- 如果有 20 名员工,则只显示 20 列)。默认情况下,所有这 60 列都是隐藏的。但是当将 40 多名员工的数据加载到网格浏览器时,显示没有响应。即,显示/隐藏列需要时间。
请检查我加载数据的代码
$.ajax({
type: "POST",
url: '@Url.Action("GetData", "Employees")',
dataType: "json",
data: param,
success: function (response) {
if (response != null) {
var empList = response.Employees;
grid.dataSource.data([]);
grid.dataSource.data(response.Items);
//To change the name header and hide/show crew name column
if (empList != null) {
var listIndex = 0;
$('#grdEmployees th[coltype]').each(function (i) {
if ($(this).data().title == "HideColumn") {
var dataField = "Crew" + (listIndex + 1);
$("#grdEmployees thead [data-field=" + dataField + "] .k-link").html(empList[listIndex].Name.toString());
if (empList[listIndex].Name.toString() == "HideColumn") {
$('#grdEmployees').data("kendoGrid").hideColumn(dataField);
} else {
$('#grdEmployees').data("kendoGrid").showColumn(dataField);
}
listIndex++;
}
});
}
}
},
error: function (err) {
console.log(JSON.stringify(err));
}
});
请让我知道执行相同操作的任何替代解决方案。
最佳答案
我已经解决了这个问题。当我们使用剑道网格的 hideColumn()
和 showColumn()
方法时,需要花费一些时间。所以我只是用普通的 jQuery hide()
和 show()
方法替换它。
检查下面的代码
我已经替换了
if (empList[listIndex].Name.toString() == "HideColumn") {
$('#grdEmployees').data("kendoGrid").hideColumn(dataField);
} else {
$('#grdEmployees').data("kendoGrid").showColumn(dataField);
}
与
var colIdx = $(this).index() + 1;
if (crewNameList[listIndex].Name.toString() == "HideColumn") {
$("#grdEmployees table th:nth-child(" + colIdx + "),td:nth-child(" + (colIdx) + "),col:nth-child(" + (colIdx-1) + ")").hide();
} else {
$("#grdEmployees table th:nth-child(" + (colIdx) + "),td:nth-child(" + (colIdx) + "),col:nth-child(" + (colIdx-1) + ")").show();
}
这对你很有用。
关于javascript - Kendo 网格列显示/隐藏 80 多个列出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30167893/