DataTables warning (table id = 'myDataTable'): Requested unknown parameter '0' from the data source
DataTables warning (table id = 'myDataTable'): Requested unknown parameter '0' from the data source
I get this error when I add a new row to the table. However the new row is added to the table with empty consultantName field. Also I think its imp to mention that the next time when I access the table( when I refresh the table) I see the consultant name field has correct data.
the link for debugger http://debug.datatables.net/opivip
Below is my code for datatable
[code]
$(document).ready(function () {
$('#myDataTable').dataTable().makeEditable({
sUpdateURL: "/DataEntry/UpdateData",
sAddURL: "/DataEntry/AddData"
});
});
ConsultantName
Week
Hours
BillableRateRT
BillableRateOT
PayableRateRT
PayableRateOT
Currency
@foreach (var item in Model)
{
@item.ConsultantName
@item.Week.ToShortDateString() @*to get date only*@
@item.Hours
@item.BillableRateRT
@item.BillableRateOT
@item.PayableRateRT
@item.PayableRateOT
@item.Currency
}
[/code]
and here is the the code for add row form
[code]
@{
IQueryable ConsultantNameList = DropdownUitility.getConsultantsforCompany(Model);
}
ConsultantName
@{
int count = 0;
// String name = null;
foreach (var name in ConsultantNameList)
{
count++;
@name
}
}
@*
hellono
helloyes
*@
Week
Hours
BillableRateRT
BillableRateOT
PayableRateRT
PayableRateOT
Currency
[/code]
and this is my addData Function
[code]
public int AddData(string ConsultantName, string week, string hours, string BillableRateRT, string BillableRateOT, string PayableRateRT, string PayableRateOT, string currency)
{
//int a = 1;
//return a;
DateTime wek = Convert.ToDateTime(week);
var cc=db.Consultants.First(d => d.ConsultantName.ToLower().Equals(ConsultantName.ToLower())).ConsultantID; //so that i get a int value of conID insteatd of Iquerable
//var conId= from c in db.Consultants
// where (c.ConsultantName.ToLower().Equals(name.ToLower()))
// select c.ConsultantID;
var consu = from ww in db.WeeklyHours
where (ww.ConsultantID == cc && (ww.Week.Year == wek.Year && ww.Week.Month == wek.Month && ww.Week.Day == wek.Day))
select ww.ConsultantID;
if (consu.Any())
{
Response.Write(ConsultantName + " work hours for" + week + "' already exists");
Response.StatusCode = 404;
Response.End();
return -1;
}
var weeklydata = from q in db.WeeklyHours
select q;
var wh = new WeeklyHour();
wh.ConsultantID = cc;
wh.ConsultantName = ConsultantName;
wh.Week = Convert.ToDateTime(week);
wh.Hours = Convert.ToInt32(hours);
wh.BillableRateRT = Convert.ToDecimal(BillableRateRT);
wh.BillableRateOT = Convert.ToDecimal(BillableRateOT);
wh.PayableRateRT = Convert.ToDecimal(PayableRateRT);
wh.PayableRateOT = Convert.ToDecimal(PayableRateOT);
wh.Currency = currency;
db.WeeklyHours.Add(wh);
try
{
db.SaveChanges();
}
catch (Exception e)
{
Console.WriteLine(e);
// Provide for exceptions.
}
return wh.ConsultantID;
}[/code]
the link for debugger http://debug.datatables.net/opivip
Below is my code for datatable
[code]
$(document).ready(function () {
$('#myDataTable').dataTable().makeEditable({
sUpdateURL: "/DataEntry/UpdateData",
sAddURL: "/DataEntry/AddData"
});
});
ConsultantName
Week
Hours
BillableRateRT
BillableRateOT
PayableRateRT
PayableRateOT
Currency
@foreach (var item in Model)
{
@item.ConsultantName
@item.Week.ToShortDateString() @*to get date only*@
@item.Hours
@item.BillableRateRT
@item.BillableRateOT
@item.PayableRateRT
@item.PayableRateOT
@item.Currency
}
[/code]
and here is the the code for add row form
[code]
@{
IQueryable ConsultantNameList = DropdownUitility.getConsultantsforCompany(Model);
}
ConsultantName
@{
int count = 0;
// String name = null;
foreach (var name in ConsultantNameList)
{
count++;
@name
}
}
@*
hellono
helloyes
*@
Week
Hours
BillableRateRT
BillableRateOT
PayableRateRT
PayableRateOT
Currency
[/code]
and this is my addData Function
[code]
public int AddData(string ConsultantName, string week, string hours, string BillableRateRT, string BillableRateOT, string PayableRateRT, string PayableRateOT, string currency)
{
//int a = 1;
//return a;
DateTime wek = Convert.ToDateTime(week);
var cc=db.Consultants.First(d => d.ConsultantName.ToLower().Equals(ConsultantName.ToLower())).ConsultantID; //so that i get a int value of conID insteatd of Iquerable
//var conId= from c in db.Consultants
// where (c.ConsultantName.ToLower().Equals(name.ToLower()))
// select c.ConsultantID;
var consu = from ww in db.WeeklyHours
where (ww.ConsultantID == cc && (ww.Week.Year == wek.Year && ww.Week.Month == wek.Month && ww.Week.Day == wek.Day))
select ww.ConsultantID;
if (consu.Any())
{
Response.Write(ConsultantName + " work hours for" + week + "' already exists");
Response.StatusCode = 404;
Response.End();
return -1;
}
var weeklydata = from q in db.WeeklyHours
select q;
var wh = new WeeklyHour();
wh.ConsultantID = cc;
wh.ConsultantName = ConsultantName;
wh.Week = Convert.ToDateTime(week);
wh.Hours = Convert.ToInt32(hours);
wh.BillableRateRT = Convert.ToDecimal(BillableRateRT);
wh.BillableRateOT = Convert.ToDecimal(BillableRateOT);
wh.PayableRateRT = Convert.ToDecimal(PayableRateRT);
wh.PayableRateOT = Convert.ToDecimal(PayableRateOT);
wh.Currency = currency;
db.WeeklyHours.Add(wh);
try
{
db.SaveChanges();
}
catch (Exception e)
{
Console.WriteLine(e);
// Provide for exceptions.
}
return wh.ConsultantID;
}[/code]
This discussion has been closed.
Replies
Allan
WRONG :
[code]
@{
int count = 0;
foreach (var name in ConsultantNameList)
{
count++;
@name
}
}
[/code]
select should have the rel attribute which the editable plugin uses to match data to column. In my previous code I put the rel attribute in the Options tag which was wrong.
CORRECT:
[code]
@{
int count = 0;
foreach (var name in ConsultantNameList)
{
count++;
@name
}
}
[/code]