简体   繁体   English

MvcContrib网格中的分层数据

[英]Hierarchical data in MvcContrib Grid

Is it possible to show a class with a nested IEnumerable property within MvContribGrid such as... 是否可以在MvContribGrid中显示带有嵌套IEnumerable属性的类,例如...

public class ParentViewModel
{
    IEnumerable<Parent> Parents {get;set;}
}

public Class Parent
{
     public string Name{get;set;}
     public IEnumerable<Children> Children {get;set}
}

I had similar requirement, but i used ajax for Hierarchical information showing. 我有类似的要求,但是我使用ajax来显示层次结构信息。 It help me two ways. 它对我有两种帮助。 One the child information is loaded when requested. 当请求时加载一个子信息。 so i dont have to load all information on one go and also helped in multiple level Hierarchy. 因此,我不必一次加载所有信息,也可以帮助进行多层次的层次结构设计。

I used Jquery Datatable along with mvccontrib grid for pagination search and for Hierarchical data expand collapse link were introduced 我用jQuery的数据表连同mvccontrib网格分页搜索和分层数据展开收起链接介绍

Updated: In my exmple i have created first column with some concat information on first column which is required me to identify the row i have clicked. 更新:在我exmple我已经创建了第一列与要求我找出我点击了该行的第一列一些CONCAT信息。 class .expand is to tell on click it should be expanded.a $.ajax call be made and information retrieved will be appended to the clicked row. class .expand表示单击时应将其扩展。将进行$ .ajax调用,并将检索到的信息附加到单击的行。 expand/collapse are js method. 扩展/折叠都是js方法。 you will see below this code. 您将在此代码下方看到。

<%Html.Grid(Model)
    .Columns(column =>
            {%>
            <% <td><a id="<%= c.Desc %>_<%= c.No %>" href="#" class="expand"></a></td>                
            <% }).Attributes(c => new Dictionary<string, object> { { "padding-left", " 5px" } });                
                column.For(c => c.Date).Format("{0:dd/MM/yyyy}").Named("Date");
                column.For(c => c.Desc).Named("Description");                   
               }).Attributes(id => "example")
            .Empty("----------- No Ledger Details for current month/Search -----------    ").Render();%>

I used jquery datatable for pagination and search in populated rows.and also used tabletool plugin for jquery datatable which help in exporting result to csv/xls/pdf. 我使用jquery数据表进行分页并在填充的行中进行搜索。还使用tabletool插件来生成jquery数据表,这有助于将结果导出到csv / xls / pdf。 and copy pasting my content. 并复制粘贴我的内容。

 <script language="javascript" type="text/javascript">
  $(document).ready(function () {
    $('#example').dataTable({
        "sDom": 'T<"clear">lfrtip',
        "bProcessing": true,
        "bPaginate": true,
        "sPaginationType": "full_numbers",
        "bFilter": true,
        "iDisplayLength": 10,
        "bSort": false,
        "oTableTools": {
            "sRowSelect": "multi",
            "sSwfPath": "../../../../Content/media/swf/copy_cvs_xls_pdf.swf",
            "aButtons": ["select_all", "select_none", "copy", "print", {
                "sExtends": "collection",
                "sButtonText": "Save",
                "aButtons": ["csv", "xls", "pdf"]
            }]
        }
    });

});
</script>

For collapse/Expand 用于折叠/展开

$("#example a.collapse").live('click', function (event) {
            event.preventDefault();
            $(this).closest('tr').next().slideUp().remove();
            $(this).removeClass("expand");
            $(this).addClass("collapse");
        });
        $("#example a.expand").live('click', function (event) {
            event.preventDefault();
            var parent = $(this).closest('tr');
            var linkid = $(this).attr('id');
            var parts = linkid.split("_");
            var billNo = parts[1];                
            loadBillDetails(parent, billNo);                
            $(this).removeClass("collapse");
            $(this).addClass("expand");
        });

        function loadBillDetails(parent, billNo) {
            var defaultParameters = "{BillNo:" + billNo + "}";
            $.ajax({
                type: "POST",
                url: '<%=Url.Action("GetBillDetails", "Order") %>',
                data: defaultParameters,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: (function (data) {
                    var str = "<tr style='padding:5px;'><td colspan=7><div style='width: 850px; max-height: 300px; overflow: auto; background-color: #F4F4F4;'>";
                    str += "<table width='100%' id='billDetails'><tr align='left'><th>BillNo</th><th>ProductName</th><th>OrderNo</th><th>RollNo</th><th>Qty</th><th>Rate</th><th></th><th></th><th></th><th></th></tr>";
                    if (data.BillDetails.length > 0) {
                        for (var y = 0; y < data.BillDetails.length; y++) {
                            str += "<tr><td>" + data.BillDetails[y].FinalBillNo + "</td><td>" + data.BillDetails[y].ProductName + "</td><td>" + data.BillDetails[y].OrderNo + "</td><td>" + data.BillDetails[y].RollsNo + "</td><td>" + data.BillDetails[y].Qty + "</td><td>" + data.BillDetails[y].Rate + "</td><td></td><td></td><td></td></tr>";
                        }
                        str += "</table></div></td></tr>";
                    }
                    else {
                        str = "<tr style='padding:7px;'><td colspan=6>No order found.</td></tr>";
                    }
                    var newRow = $(str);
                    parent.after(newRow).slideDown();
                }),
                error: (function () {
                    parent.after("<tr style='padding:5px;'><td colspan=5>An Error has occurred.</td></tr>");
                })
            });
        }

    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM