DataTable 中的隐藏行扩展
我对数据表中的隐藏行有疑问。我知道这里提供了一个示例 http://datatables.net/examples/api /row_details.html,但我的情况有点不同。
我有一个 ElementGroupViewModel
,其中包含 ElementViewModel PrimaryElement
和 ElementViewModel[] LinkedElement
。在 DataTable 中,每一行都包含一个 Element
。在我的视图中,我有类似这样的内容
foreach ( var item in Model )
{
@Html.Partial( "_ResultItem", item.PrimaryElement )
foreach ( var linkedItem in item.LinkedElement )
{
@Html.Partial( "_ResultItem", linkedItem )
}
}
,我希望它首先显示 PrimaryElement
,并且用户可以展开/折叠每一行以显示/隐藏 LinkedElement
。另外,我希望每个页面显示 30 个 PrimaryElement
记录,无论显示多少个 LinkedElements
。
我不知道如何才能实现这一目标。有人有什么想法吗?谢谢!
I have a question about hidden rows in DataTable. I'm aware that there is an example provided here at http://datatables.net/examples/api/row_details.html, but my situation is a little bit different.
I have an ElementGroupViewModel
that contains an ElementViewModel PrimaryElement
and ElementViewModel[] LinkedElement
. In the DataTable, each row contains an Element
. In my View, I have something like this
foreach ( var item in Model )
{
@Html.Partial( "_ResultItem", item.PrimaryElement )
foreach ( var linkedItem in item.LinkedElement )
{
@Html.Partial( "_ResultItem", linkedItem )
}
}
I want it to show PrimaryElement
first, and a user can expand/collapse each row to show/hide LinkedElement
. Also, I want each page to show 30 PrimaryElement
records regardless of how many LinkedElements
are shown.
I'm not sure how I can achieve this. Anyone has any ideas? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用此结构,因为您正在生成与 DataTable 源不兼容的嵌套静态表。
您能否使用不带链接元素的主要元素生成主要主表,并进行 Ajax 调用,从另一个控制器加载链接元素的 HTML,并将其加载到 fnOpen 中。您可以在 http://www.codeproject.com/KB 上找到示例/aspnet/Expandabe-DataTable-MVC.aspx
如果您不想进行 Ajax 调用,您可以将每个链接的子数组生成为单独的隐藏表,例如:
并替换代码项目示例中的 Ajax 调用与一些JQuery 通过行的 id 查找链接表并将链接表内部 HTML 传递给 fnOpen。
我希望你能明白这里的想法是什么。
约万
You cannot use this structure because you are generating a nested static table that would not be compatible with DataTable source.
Could you generate primary master table using the primary elements without linked elements, and make Ajax calls that loads HTML for linked element from another controller, and load it in the fnOpen. You can find example on the http://www.codeproject.com/KB/aspnet/Expandabe-DataTable-MVC.aspx
If you do not want to make Ajax calls you can generate each linked sub-array as a separate hidden tables something like:
and replace Ajax call from the example on the code project with some JQuery that finds linked table by the id of the row and pass the linked table inner HTML to fnOpen.
I hope that you see what is idea here.
Jovan