简体   繁体   English

扩展HTML网格以在Html网格末尾添加div(MVC Contrib)

[英]Extend the HTML Grid for adding div at the end of Html Grid (MVC Contrib)

I have search the web to find a syntax or a guide to this but with no success. 我已经在网上搜索以找到语法或指南,但是没有成功。

I will appreciate any help. 我将不胜感激。

I have implemented a Grid in a view, and instead of using the paging of the grid view i am trying to implement a button "View More" at the end of the grid that load more data to the grid view. 我已经在视图中实现了网格,而不是尝试使用网格视图的分页,而是尝试在网格末尾实现按钮“ View More”,以将更多数据加载到网格视图中。

See the code 看代码

@Html.Grid(Model.Orders).Columns(columns =>
        {
            columns.For(c => @Html.AddInstitudeRetangle(c.User.Institute.InstitudeColor, c.User.Institute.InstituteName)).Named("");
            columns.For(c => @Html.CheckBox(c.OrderID.ToString(), false, new { @ID = "cb-" + c.OrderID.ToString(), @Name = "cb-" + c.OrderID.ToString() })).Header("<th><input type=\"checkbox\" id=\"chkHeader\" /></th>");
            columns.For(c => @Ajax.LinkForBootstrapModalNo("OrderDetails", "OrdersManagement", c.OrderID.ToString(), new { OrderID = c.OrderID }, new { id = "OrderID" }).LoadingPanel("Please Wait Loading...").ToMVCHtmlString()).Named(OrdersManagementStrings.OrderID);
            columns.For(c => @Html.GetOrderTypeIcon(c.OrderTypeStatus, c.OrderTypeStatus.GetDescription())).Named(OrdersManagementStrings.OrderType);
            columns.For(c => String.Format("{0:dd/MM/yyyy hh:mm}", c.CreationDate)).Named(OrdersManagementStrings.OrderDate);
            columns.For(c => String.Format("{0} {1}", c.User.FirstName, c.User.LastName)).Named(OrdersManagementStrings.CustomerName);
            columns.For(c => c.User.Institute.InstituteName).Named(OrdersManagementStrings.AffiliateName);
            columns.For(c => c.TotalCost).Named(OrdersManagementStrings.TotalCost);
            columns.For(c => c.ShippingTypeEnum.GetDescription()).Named(OrdersManagementStrings.ShippingType);
            columns.For(c => c.Address.FullAddress).Named(OrdersManagementStrings.Address);
            columns.For(c => c.OrderStatusEnum.GetDescription()).Named(OrdersManagementStrings.OrderStatus);
        }).Attributes(@class => "table table-hover table-responsive table-condensed", @id => "ordersTable")

        <div id="scroll" data-itemsperpage="50" data-spy="scroll">Load More</div

Now when a user clicks on the div at the end i am using ajax request to load more data. 现在,当用户最后单击div时,我正在使用ajax请求来加载更多数据。

Now, i want to create an extension the will add this div to the end of the Grid. 现在,我想创建一个扩展 ,它将将该div添加到网格的末尾。

So at the end the syntax will be something as 所以最后的语法将是

columns.For(c => c.OrderStatusEnum.GetDescription())
.Named(OrdersManagementStrings.OrderStatus);
            })
.Attributes(@class => "table table-hover table-responsive table-condensed", @id => "ordersTable")
.LoadMoreButton(50);

The number 50 represent the number of rows per page 数字50表示每页的行数

After looking through the source, I think it might be easier to extend HtmlTableGridRenderer as a ScrollingHtmlTableGridRenderer and use 在查看了源代码之后,我认为将HtmlTableGridRenderer扩展为ScrollingHtmlTableGridRenderer并使用它可能会更容易

@Html.Grid(Model.Orders)
     .RenderUsing(new ScrollingHtmlTableGridRenderer(50))
     ...

then in ScrollingHtmlTableGridRenderer override RenderGridEnd to add the extra DIV 然后在ScrollingHtmlTableGridRenderer覆盖RenderGridEnd以添加额外的DIV

public class ScrollingHtmlTableGridRenderer<T> : HtmlTableGridRenderer<T>
    where T : class
{
     private readonly int _itemsPerPage;

     public ScrollingHtmlTableGridRenderer(int itemsPerPage)
     {
          _itemsPerPage = itemsPerPage;
     }

     protected override void RenderGridEnd()
     {
          base.RenderGridEnd();
          RenderText("<div id=\"scroll\" data-itemsperpage=\"" + _itemsPerPage + \"" data-spy=\"scroll\">Load More</div>");
     }
}

You might be able to do this as an extension that basically creates a new renderer and propagates all the data from the underlying grid model to it, but the Grid class seems to be built to be extended by replacing the renderer with one that handles your custom needs rather than by extensions on IGridOptionsModel . 您可能可以通过做一个扩展来做到这一点,该扩展基本上可以创建一个新的渲染器并将所有数据从底层网格模型传播到该渲染器,但是通过将渲染器替换为可以处理自定义样式的渲染器,似乎可以扩展Grid类。需要,而不是通过IGridOptionsModel的扩展。

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

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