将WebGrid Helper和Column用作隐藏项时,默认排序不起作用 [英] Default Sort is not working while using WebGrid Helper With Column as hidden
问题描述
我正在使用@grid.GetHtml
gridview在ASP.NET MVC4应用程序中显示网格.
I am using @grid.GetHtml
gridview to show the grid in my ASP.NET MVC4 application.
在使用隐藏列(主键)的WebGrid Helper时,默认排序不起作用.
Default Sort is not working while using WebGrid Helper With Column (Primary Key) as hidden.
使用SP来获取Web网格数据,并且SP中也提供了默认排序.
Using SP to fetch the web grid data and also default sort is given in SP.
我的代码:
@grid.GetHtml(
htmlAttributes: new
{
id = "XXXX"
},
tableStyle: "table table-bordered table-condensed table-hover table-striped",
headerStyle: "info",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "gridrow",
columns: grid.Columns(
grid.Column("AAAA", "AAAA",style:"hidecol") //Primary Column Name is "AAAA"
)
)
jQuery代码隐藏主列的列标题.
JQuery Code to hide Column Header of Primary Column.
<script type="text/javascript">
$(document).ready(function() {
$("# XXXX th:nth-child(1)").hide();
});
</script>
推荐答案
您可以在将控件传递给视图之前对它们进行排序.这样,他们应该保留您想要的顺序:
You could just sort the items in your controller before passing them to the view. That way they should retain the order you want:
public IActionResult Index()
{
var items = new List<obj>(){new obj(5), new obj(1), new obj(355)};
var sortedItems = items.OrderBy(o => o.Id);
return View(sortedItems);
}
如果您需要一种在视图本身中对它们进行排序的方法,则可以执行
And if you need a way from sorting them in the view itself, you can do something like
public IActionResult Index(string sortOrder)
{
var items = new List<obj>(){new obj(5), new obj(1), new obj(355)};
if (sortOrder == "ASC")
{
items = items.OrderBy(o => o.Id).ToList();
}
return View(items);
}
通过按钮或视图中所需的任何按钮调用该控制器的地方
Where you call that controller from a button or whatever you need in your view
这篇关于将WebGrid Helper和Column用作隐藏项时,默认排序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!