[英]How to add custom div structure, accessible by id, to the devExpress dxDataGrid cell?
How to add the following custom div structure to the dxDataGrid cell (or cellTemplate): 如何将以下自定义div结构添加到dxDataGrid单元格(或cellTemplate):
<div class="some_class_1" id="some_id">
<div class="some_class_2">some_text</div>
</div>.
I must to have access to any of these divs by it's unique id ('some_id' in an example). 我必须通过其唯一ID(在示例中为“ some_id”)来访问所有这些div。
I try this: 我尝试这样:
cellTemplate: function (container) {
$('<div/>').attr('id', 'some_id').addClass('some_class_1')
.add("div").addClass('some_class_2').text('some_text')
.appendTo(container);
}
...that's not work. ...那是行不通的。
It is good to see snippet. 很高兴看到摘要。 Thanx in advance.
提前感谢。
You have to put new element and return it: 您必须放入新元素并将其返回:
cellTemplate: function (container) {
return $('<div/>').attr('id', 'some_id'+$(container).index()).addClass('some_class_1')
.append($("<div>").addClass('some_class_2').text('some_text'))
.appendTo(container);
}
Jai solution works. Jai解决方案有效。 And this alternative works fine too:
这个替代方案也很好:
cellTemplate: function (container) {
$("<div>")
.addClass('some_class_2')
.text('some_text')
.appendTo($('<div>')
.attr('id', 'some_id')
.addClass('some_class_1')
.appendTo(container));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.