rows does not update after inline edit
rows does not update after inline edit
burckardas
Posts: 5Questions: 3Answers: 0
Hi,
I am using datatable editor and i would like to use entityframework.
I could update the data on sql but datatable does not refresh row after edit.
var formData = HttpContext.Request.Form;
if (formData.Count>1)
{
var keys = formData.AllKeys;
var action = formData["action"];
int pFrom = keys[1].IndexOf("data[") + "data[".Length;
int pTo = keys[1].LastIndexOf("][");
String updatedid = keys[1].Substring(pFrom, pTo - pFrom);
int updateid = Convert.ToInt32(updatedid);
int pFrom2 = keys[1].IndexOf("][") + "][".Length;
int pTo2 = keys[1].LastIndexOf("]");
String column= keys[1].Substring(pFrom2, pTo2 - pFrom2);
var value = formData[keys[1]];
if (action=="edit")
{
string sqlcommand = string.Format(@"update AppaMVC..lineitems set {0}='{1}' where id={2}", column, value, updateid);
_context.Database.ExecuteSqlCommand(sqlcommand);
}
var lineitem = _context.LineItems.Select(x => new LineItemEditModel
{
Number = x.Number,
Impa = x.Impa,
Description = x.Description,
Unit = x.Unit,
Qtty = x.Qtty,
Price = x.Price,
Remark = x.Remark,
AltUnit = x.AltUnit,
AltQtty = x.AltQtty,
AltPrice = x.AltPrice,
SelectedSupplierName = x.SelectedSupplierName,
SelectedSupplierCalculatedPrice = x.SelectedSupplierCalculatedPrice,
RealCost = x.RealCost,
Id = x.Id,
SelectedSupplierRemark = x.SelectedSupplierRemark,
ReferanceNumberId = x.ReferanceNumberId,
IsRemoved = x.IsRemoved,
MasterNumber = x.MasterNumber
}
).Where(a => a.Id==updateid).FirstOrDefault();
lineitem.DT_RowId = "row_" + updatedid;
return Json(
new
{
aaData = lineitem
}
, JsonRequestBehavior.AllowGet);
}
else
{
var lineitems = _context.LineItems.Select(x => new LineItemEditModel
{
Number = x.Number,
Impa = x.Impa,
Description = x.Description,
Unit = x.Unit,
Qtty = x.Qtty,
Price = x.Price,
Remark = x.Remark,
AltUnit = x.AltUnit,
AltQtty = x.AltQtty,
AltPrice = x.AltPrice,
SelectedSupplierName = x.SelectedSupplierName,
SelectedSupplierCalculatedPrice = x.SelectedSupplierCalculatedPrice,
RealCost = x.RealCost,
Id = x.Id,
SelectedSupplierRemark = x.SelectedSupplierRemark,
ReferanceNumberId = x.ReferanceNumberId,
IsRemoved = x.IsRemoved,
MasterNumber = x.MasterNumber,
DT_RowId="row_"+x.Id
}
).Where(a => a.ReferanceNumberId == id && a.IsRemoved == false).ToList();
var itemsordered = lineitems.OrderBy(l => l.MasterNumber == "0" ? int.Parse(l.Number) : int.Parse(l.MasterNumber)).ToList();
return Json(
new
{
aaData = itemsordered,
iTotalDisplayRecords = lineitems.Count(),
iTotalRecords = lineitems.Count(),
idSrc = "Id"
}
, JsonRequestBehavior.AllowGet);
}
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
Hi @burckardas ,
If the table isn't updating after the edit, that's normally caused by incorrect data being returned by the server. Please can you post the server's response to your edit.
Cheers,
Colin