【问题标题】:MVCContrib Grid alternatives for MVC4MVC4 的 MVCContrib 网格替代品
【发布时间】:2012-12-22 09:38:39
【问题描述】:

我正在开发一个全新的 MVC4 项目,我需要一个好的 MVC 网格来支持分页和排序(我想自己处理分页和排序,而不是在网格中)。我也喜欢轻量级的网格(因为我想控制 html 标记和查询参数)并且能够对列使用 lambda 表达式。

我之前在一个较旧的 MVC2 项目中使用过 MvcContrib Grid,并且对它的可扩展性非常满意。我在这个项目中对 webhelper 网格进行了一些实验,但它似乎不像 MvcContrib Grid 那样可扩展。然而,MvcContrib 项目似乎不再得到积极维护。据我所知,主要版本是针对 MVC2 的,我真的不想在全新的未开发项目中发布兼容性。

有谁知道 MvcContrib 项目是否有望发布 MVC4 的新版本?现在还有其他适用于 MVC 的轻量级和最新的网格吗?

更新 我最终编写了自己的网格组件(和一个寻呼机组件),其语法风格松散地基于 MvcContrib,并且可以交换渲染器。

【问题讨论】:

  • MVC4没有asp gridview

标签: asp.net-mvc-4 mvccontrib mvccontrib-grid


【解决方案1】:

你看过 jQuery Datatables http://www.datatables.net/

我最近从 MVCContrib Grid 迁移到 jQuery Datatables。他们非常棒。

这是我们初始化表格的方式。

BindTable: function () {
        var that = this;
        this.Table = $('#sorting-advanced');
        var tableStyled = false;

        this.Table.dataTable({
            'aoColumnDefs': [
                { 'aTargets': [1], 'sType': 'num-html' },
                { 'aTargets': [3], 'sType': 'currency' },
                { 'aTargets': [5], 'bSortable': false, }
            ],
            'sPaginationType': 'full_numbers',
            'sDom': '<"dataTables_header"lfr>t<"dataTables_footer"ip>',
            'fnDrawCallback': function (oSettings) {
                // Only run once
                if (!tableStyled) {
                    that.Table.closest('.dataTables_wrapper').find('.dataTables_length select').addClass('select').styleSelect();
                    tableStyled = true;
                }
            }
        });
    },

这是剃刀视图

  <table class="table responsive-table" id="sorting-advanced">
            <thead>
                <tr>
                    <th scope="col">Date</th>
                    <th scope="col">Document #</th>
                    <th scope="col">Tenant</th>
                    <th scope="col">Amount</th>
                    <th scope="col" class="align-center">Reconciled</th>
                    <th scope="col" class="align-center">Actions</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.Items)
                {
                    <tr>
                        <td>@item.Date.ToShortDateString()</td>
                        <td>
                            <a href="@Url.Action("Edit", new {id = item.Id})">@item.Number</a>
                        </td>
                        <td>@item.Contact.DisplayName</td>
                        <td>@item.Amount.ToString("C2")</td>
                        <td class="align-center">
                          @Html.CheckBoxFor(x => item.Reconciled, new {id = item.Id})
                        </td>
                        <td class="align-center vertical-center">
                            <span class="button-group compact">

                                <a href="@Url.Action("Edit", new {id = item.Id})" 
                                   class="button icon-pencil with-tooltip"
                                   title="Edit Payment"></a>

                                <a href="#" id="@item.Id" 
                                   class="button icon-trash with-tooltip confirm-delete"
                                   title="Delete Payment"></a>
                            </span>
                        </td>
                    </tr>
                }
            </tbody>
        </table>

【讨论】:

  • 我看到它被提到,因为我正在寻找一点,但我有点反对我看到的 jQuery 版本,派对,因为它们中的大多数“class-barfs”有点,使得标记(至少在我看来)太乱了。此外,在我看来,您需要一些配置来映射您的视图模型和您的 javascript,如果您进行一些重构(如更改属性名称等),这些配置将不会更新。这就是为什么我更喜欢尽可能使用强类型网格...
  • 这不是我的经验。我可以发布一些来自实际实现的示例代码,看看你的想法。
  • 我不必将数据映射到 javascript 对象。我刚刚使用非常标准的 html 构建了表格,然后初始化了表格。你可以用它做更多的事情,但它非常简单。
  • 当然,看到一个没有花里胡哨的实际实现会很有趣。
  • 所以如果理解正确,你将所有项目一次加载到表中,然后让 Datatables 框架处理分页和排序而不重新加载页面,对吗?
猜你喜欢
  • 2012-08-29
  • 2019-11-06
  • 2011-07-22
  • 2018-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
相关资源
最近更新 更多