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

ariz1185ariz1185 Posts: 2Questions: 0Answers: 0
edited August 2013 in General
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]

Replies

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    It sounds like an error with the makeEditable plug-in since you get this error when you add a new row with that plug-in. makeEditable is not provided or supported as part of the DataTables project - it is third party software, so you might be best asking on their issue tracker. Having said that, I understand that it is now deprecated so I'm not sure how much support will be available. Sorry.

    Allan
  • ariz1185ariz1185 Posts: 2Questions: 0Answers: 0
    Thanks for helping Allan. I found the bug, it was the rel attribute in the html selectList for ConsultantNames.

    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]
This discussion has been closed.