2

我在 ASP.NET MVC 3 Razor 中开发了一个 web 应用程序。我一直在使用 WebGrid 列出表格数据,并想用 webgrid 做 xxx 事情。

1. 我想让 WebGrid 显示哪一列是排序列,以及它是升序还是降序。 我找不到似乎可以满足我愿望的任何 WebGrid 属性。而且我在互联网上找不到任何东西...

2. 我想为所有列标题添加一个工具提示(每个标题的工具提示不同)。显然那里有大量的 javascript 工具提示,但我还没有找到可以在 WebGrid 中使用的任何东西......

4

2 回答 2

1

对于 q2:为您的 WebGrid 助手提供一个 ID

htmlAttributes:new{id="GridID"}

然后使用 Jquery 为所有标题添加标题 $('table#GridID th').each(function() { $(this).attr('title', $(this).text()); });

于 2012-10-08T09:55:26.577 回答
0

对于排序的东西,你可以看看这篇文章:

System.Web.Helpers.WebGrid 中的排序指示器

在视图中,您可以这样做:

// Force a descending sort only when no user specified sort is present
if (Request.QueryString[grid.SortDirectionFieldName].IsEmpty())
{
    grid.SortDirection = SortDirection.Descending;
}

然后是自定义 JavaScript:

displaySortIndicators('@grid.SortColumn', '@grid.SortDirection');

displaySortIndicators = function (column, sortDirection) {

    if (column != '') {

        var th = $('thead > tr > th > a[href*="sort=' + column + '"]');

        th.append((sortDirection == 'Ascending') ? "▲" : "▼");
    }
}

对于工具提示,您可以使用qTip2

注意:我将上面链接中的两种方法与 WebGrid 帮助程序一起使用,它们按预期工作。

于 2012-03-03T05:18:09.440 回答