[英]Get child elements from a specific cell in an HTMLTableRowElement and hide/remove them?
我正在使用Telerik的MVC网格使用一些自定义ajax功能,并且尝试根据特定条件隐藏/删除单元格的子元素,我在这里发现了一个类似的问题: Telerik MVC网格根据其他列的值使列为红色但无法正常工作。
基本上,当行在网格中数据绑定时,此事件将触发:
function onRowDataBound(e) {
if (e.dataItem.Status == "Submitted") {
$.each(e.row.cells, function (index, column) {
alert(column.innerHTML);
//var $header = $(column).closest('table').find('th').eq($(column).index());
//if(header text == "Actions)
//{
//Get the <a> child elements in the 'Actions' column whose class contains t-grid-Edit,
//t-grid-edit, t-grid-Delete, or t-grid-delete and set their display to none, add a css class, and remove the element entirely
//}
}
}
}
到目前为止,它的工作原理是我可以获取并遍历行中的每一列,但我不知道此时该怎么做,我发现了如何从表格单元格中获取相应的表格标题(t) )? 检查以确保列名称名称为Actions,但我无法使其正常工作。 我不知道如何将javascript HTMLTableCellElement对象转换为jQuery对象,因此我可以使用我更熟悉的语法。
以下是我之后需要做的事情:
采取这些元素和(这些操作中的每一个将使用类似的设置在不同的页面上使用):
一种。 将元素的显示样式设置为无
湾 将一个类添加到名称为“隐藏”的元素中
C。 从代码中完全删除元素
如何将上述功能放入我的onRowDataBound
函数中?
谢谢SO =)。
我能够通过大量的游戏来解决这个问题:
function onRowDataBound(e) {
if(e.dataItem.Status == "Submitted"){
var $row = $(e.row);
$.each($row.children("td"), function (index, column) {
var $column = $(column);
var $headerText = $column.closest('table').find('th').eq($column.index()).children(".t-link").text();
if ($headerText == "Actions") {
$.each($column.children("a.t-grid-delete, a.t-grid-Edit"), function (subIndex, link) {
$(link).remove();
});
}
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.