简体   繁体   English

MVC中的jQuery数据表(服务器端)

[英]jQuery datatable in MVC (server-side)

https://datatables.net/usage/server-side https://datatables.net/usage/server-side

On the page above, there are parameters that you need to receive to make server-side datatable work. 在上面的页面中,您需要接收一些参数以使服务器端数据表工作。 I have a helper class 我有一个助手班

public class TableParameter
{
    public string sEcho { get; set; }
    public int iDisplayStart { get; set; }
    public int iDisplayLength { get; set; }
    public int iSortingCols { get; set; } 
}

But in order to sort columns I need to receive 但是为了排序我需要接收的列

 string sSortDir_(int)

How do I do that? 我怎么做? I know (int) represents column ID that needs to be sorted, but I just can't catch it in my controller. 我知道(int)表示需要排序的列ID,但我无法在我的控制器中捕获它。

The datatable will post one or more sSortDir_x parameters to your controller, depending on how many columns are sorted on simultaneously in the table. 数据表将向控制器发布一个或多个sSortDir_x参数,具体取决于表中同时排序的列数。

The specific columns that the table is sorted by are sent in the iSortCol_ parameters (again, one or more). 表排序的特定列在iSortCol_参数中发送(同样,一个或多个)。

public class TableParameter
{
    public string sEcho { get; set; }
    public int iDisplayStart { get; set; }
    public int iDisplayLength { get; set; }
    public int iSortingCols { get; set; } 
    public int iSortCol_0 { get; set; } // the first (and usually only) column to be sorted by
    public string sSortDir_0 { get; set; } // the direction of the first column sort (asc/desc)
    public int iSortCol_1 { get; set; } // the second column to be sorted by
    public string sSortDir_1 { get; set; } // the direction of the second column sort
    // etc
}

For receiveing a column name in action, that is used for one-column sorting: 用于接收正在运行的列名称,用于单列排序:

public ActionResult SomeMethod(FormCollection coll)
{
    var sortingColumnNumber = Convert.ToInt32(coll["iSortCol_0"]);
    var sortingColumnName = coll[string.Format("mDataProp_{0}", sortingColumnNumber)]; 
    var propertyInfo = typeof(SomeObject).GetProperty(sortingColumnName);

    //..get List<SomeObject> sortedObjects
    sortedObjects = sortedObjects.OrderBy(x => propertyInfo.GetValue(x, null)).ToList();
    //...
}

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

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