问题描述
我正在尝试将排序,分页和过滤功能添加到我的jQuery DataTable中,但它们都没有工作。我尝试了大部分工作,但是我不知道我在这里错过了什么?我在但由于某些原因,功能不起作用。你可以帮帮我吗?
这是我的检查代码:
Hi,
I am trying to add Sorting, Paging and Filter functionalities to my jQuery DataTable, but none of them are working. I tried mostly everything I could to get this to work but don't know what am I missing here? I am following this example from CodeProject - jQuery DataTables and ASP.NET MVC Integration but for some reason the functionalities are not working. Could you please help me out?
Here's my code for your inspection:
// Pagination
List<TopPlayed> filteredTracks = daa;
var TopPlayed = filteredTracks.Skip(param.iDisplayStart).Take(param.iDisplayLength);
// Sorting
var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
Func<TopPlayed, string> orderingFunction = (c => sortColumnIndex == 1 ? c.TrackName :
sortColumnIndex == 2 ? c.TrackName : c.ArtistName);
var sortDirection = Request["sSortDir_0"]; // asc or desc
if (sortDirection == "asc")
filteredTracks = daa.OrderBy(orderingFunction).ToList();
else
filteredTracks = daa.OrderByDescending(orderingFunction).ToList();
// Filter
if (!string.IsNullOrEmpty(param.sSearch))
{
daa.Where(c => c.TrackName.Contains(param.sSearch)
||
c.ArtistName.Contains(param.sSearch)
||
c.TrackName.Contains(param.sSearch));
}
else
{
filteredTracks = daa;
}
这是我正在使用的数据:
Here's the data that I'm working with:
string Path = @"C:\\5Newwithdate-1k.xls";
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" + Path + "';Extended Properties=" + (char)34 + "Excel 8.0;IMEX=1;" + (char)34 + "");
OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", con);
con.Close();
System.Data.DataTable data = new System.Data.DataTable();
da.Fill(data);
List<TopPlayed> daa = new List<TopPlayed>();
foreach (DataRow p in data.Rows)
{
TopPlayed top = new TopPlayed()
{
TrackID = Convert.ToInt32(p.Field<double>("TrackID")),
Date = p.Field<DateTime>("DateTimes"),
TrackName = p.Field<string>("TrackName"),
ArtistName = p.Field<string>("ArtistName"),
Times = Convert.ToInt32(p.Field<double>("Times"))
};
daa.Add(top);
}
这就是我要归还的内容:
This is what I am returning:
return Json(new { sEcho = param.sEcho,
iTotalRecords = filteredTracks.ToList().Count(),
iTotalDisplayRecords = filteredTracks.ToList().Count(),
aaData = daa },
JsonRequestBehavior.AllowGet);
任何帮助都会非常有帮助..提前感谢:)
Any help would be great help.. thanks in advance :)
推荐答案
这就是我要归还的内容:
This is what I am returning:
return Json(new { sEcho = param.sEcho,
iTotalRecords = filteredTracks.ToList().Count(),
iTotalDisplayRecords = filteredTracks.ToList().Count(),
aaData = daa },
JsonRequestBehavior.AllowGet);
任何帮助都会非常有帮助..提前感谢:)
Any help would be great help.. thanks in advance :)
这篇关于在Sorting,Paging和Filter功能方面需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!