在您的數據表中,如果您想要在API中檢索名稱,則需要將名稱參數寫入該字段。檢查我的婁代碼,
.DataTable({
//rest code,
"order": [
[0, "asc"]
],
//rest code,
"columns": [
{ "data": "HireDate", name: "Date", },
//rest columns
在這裏,我的名字日期設置到外地僱傭日期。
而在我的API方法,
string _ordByColumn =
GetQueryValueByName.Get(Request.GetQueryNameValuePairs(),
"order[0].column");
string _ordColumnName =
GetQueryValueByName.Get(Request.GetQueryNameValuePairs(), "columns["
+ _ordByColumn + "].name");
string _ordDirection =
GetQueryValueByName.Get(Request.GetQueryNameValuePairs(),
"order[0].dir");
if (!string.IsNullOrEmpty(_ordByColumn))
{
switch (_ordColumnName)
{
case "Date":
{
if (string.Compare(_ordDirection, "asc") == 0)
{
//retrieve data order by Date
}
else
{
//retrieve data order by descending Date
}
break;
}
//rest cases and then default
default:
{
//retrieve data order by what ever you want
break;
}
}
}
而且我GetQueryValueByName類波紋管,
public static class GetQueryValueByName
{
public static string Get(IEnumerable<KeyValuePair<string, string>> _req,
string key)
{
return _req.FirstOrDefault(ma => string.Compare(ma.Key, key) ==
0).Value;
}
}
可以讀取查詢字符串作爲你的方式。