在您的数据表中,如果您想要在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;
}
}
可以读取查询字符串作为你的方式。