在Sorting,Paging和Filter功能方面需要帮助 [英] Need help with Sorting, Paging and Filter functionalities

查看:62
本文介绍了在Sorting,Paging和Filter功能方面需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试将排序,分页和过滤功能添加到我的jQuery DataTable中,但它们都没有工作。我尝试了大部分工作,但是我不知道我在这里错过了什么?我在 CodeProject - jQuery DataTables and ASP.NET中关注此示例MVC集成但由于某些原因,功能不起作用。你可以帮帮我吗?



这是我的检查代码:

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 :)

推荐答案

,con);
con.Close();
System.Data.DataTable data = new System.Data.DataTable();
da.Fill(data);

List< ; TopPlayed> daa = new 列表< TopPlayed>();

foreach (DataRow p in data.Rows)
{
TopPlayed top = new TopPlayed ()
{
TrackID = Convert.ToInt32(p.Field< d ouble>( TrackID)),
Date = p.Field< DateTime>( DateTimes),
TrackName = p.Field< string>( TrackName),
ArtistName = p.Field< string>( ArtistName),
Times = Convert.ToInt32(p.Field< double>( 时间))
};

daa.Add(top);
}
", 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 :)


您是否正确添加了jQuery库?还有为什么不下载代码并进行测试呢?



你可以从这里下载源代码:源代码
Have you added jQuery libraries properly ? And also why don't you download the code and test it ?

You can download the source code from here : Source code


这篇关于在Sorting,Paging和Filter功能方面需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆