Hi,
I am trying to load data from a
local excel file to
jQuery Datatables but it's not displaying it.
Could you please help me out as to why it's not displaying the data please? I mostly tried everything but can't seem to understand what am i missing here?
Here's my Controller code for your inspection:
public ActionResult AjaxHandler0(jQueryDataTableParamModel param, string StartDate = "", string EndDate = "")
{
try
{
if (Request.IsAuthenticated == true)
{
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"),
Times = Convert.ToInt32(p.Field<double>("Times"))
};
daa.Add(top);
}
var listOrder = daa.Where(i => i.Date >= Convert.ToDateTime(StartDate) && i.Date <= Convert.ToDateTime(EndDate)).ToList();
var newlist = listOrder.OrderByDescending(i => i.Times);
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = newlist.ToList().Count(),
iTotalDisplayRecords = listOrder.ToList().Count(),
aaData = data
}, JsonRequestBehavior.AllowGet);
}
return Json(new { Result = "ERROR" });
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}
I used this example and it displays everything fine:
public ActionResult AjaxHandler(jQueryDataTableParamModel param)
{
return Json(new{
sEcho = param.sEcho,
iTotalRecords = 97,
iTotalDisplayRecords = 3,
aaData = new List<string[]>()
{
new string[] {"1", "Microsoft", "Redmond", "USA"},
new string[] {"2", "Google", "Mountain View", "USA"},
new string[] {"3", "Gowi", "Pancevo", "Serbia"}
}
},
JsonRequestBehavior.AllowGet);
}
thanks in advance :)