[英]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.