jquery 使用 Class 查找 TR 的 TD 并进行更改(对于 Telerik MVC 网格)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8729830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery Find TD of TR with Class and make changes (for a Telerik MVC grid)
提问by HaBo
this is my mark up
这是我的标记
<tr class="t-detail-row">
<td class="t-hierarchy-cell"></td>
<td class="t-detail-cell" colspan="5"></td>
</tr>
I want to find the tr with class t-detail-rowand remove the child td with class t-hierarchy-celland change the colspan of td with class t-detail-cell
我想找到类t-detail-row的 tr并删除类t-hierarchy-cell的子 td 并使用类t-detail-cell更改 td 的 colspan
I tried something like this
我试过这样的事情
var newcolspan = $(e.row).find('.t-detail-row').children('td.t-detail-cell').attr('colspan');
$(e.row).find('.t-detail-row').children('td.t-hierarchy-cell').remove()
.children('td.t-detail-cell').attr('colspan',newcolspan+1);
any help would be greatly appreciated.
任何帮助将不胜感激。
More Specific Details about the situation
有关情况的更具体细节
嗨,当网格扩展被触发时,我如何调用客户端 jquery 函数。
all that i want to achieve is. when we expand the Telerik MVC grid we get this mark up in detail row
我想要实现的就是。当我们展开 Telerik MVC 网格时,我们会在详细信息行中获得此标记
<tr class="t-detail-row">
<td class="t-hierarchy-cell"></td>
<td class="t-detail-cell" colspan="5"></td>
</tr>
i want to eliminate <td class="t-hierarchy-cell"></td>
in it.
我想消除 <td class="t-hierarchy-cell"></td>
它。
and get the mark up as
并将标记标记为
<tr class="t-detail-row">
<td class="t-detail-cell" colspan="Current+1"></td>
</tr>
for this i though of doing some thing like this
为此,我虽然做了这样的事情
on grid expand event, if i can call a jquery function then because i wont have the detail-row markup generated until we expand the grid
在网格展开事件上,如果我可以调用 jquery 函数,那么因为在展开网格之前我不会生成详细信息行标记
function onExpandingtheGrid(){
$('tr.t-detail-row').find('td.t-hierarchy-cell').remove();
$('tr.t-detail-row').find('td.t-detail-cell').attr('colspan',newcolspan+1);
}
Thanks
谢谢
Solution
解决方案
只需在您的 Telerik 代码中添加这一行
.ClientEvents(exp => exp.OnDetailViewExpand("onExpandingtheGrid"))
and rest as mentioned in your above jquery function yahoo!
并按照上面的 jquery 函数 yahoo! 中提到的那样休息!
回答by Evan
with separate functions its:
具有单独的功能:
$('tr.t-detail-row').find('td.t-hierarchy-cell').remove();
$('tr.t-detail-row').find('td.t-detail-cell').attr('colspan',newcolspan+1);
i used find in this case because it looks like you are trying to use a target row for a click or something. replace the tr selector with your target if that is the case.
我在这种情况下使用了 find ,因为看起来您正在尝试使用目标行进行点击或其他操作。如果是这种情况,请将 tr 选择器替换为您的目标。
回答by techfoobar
Try this:
尝试这个:
$('tr.t-detail-row td.t-hierarchy-cell').remove();
$('tr.t-detail-row td.t-detail-cell').attr('colspan', X); // replace X with desired colspan value