editor does not fire postCreate event
editor does not fire postCreate event
mike92117
Posts: 40Questions: 12Answers: 1
The postCreate event does not seem to fire when a new row is created. The row is created but the view is not updated. I have a work around to make the grid update but I really need to hook into this event.
I verified that I can run the WebApi demos and the event does not fire there also so apparently, it isn't something I'm doing.
Can you help?
Thanks,
Mike #datatablesrocks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Without know more info my guess is that the created row is not being returned as described here:
https://editor.datatables.net/manual/server#Create
I'm not familiar with these demos. Are they on this site or somewhere else?
Kevin
these demos are included in the ZIP file download for registered users. There are different versions. I downloaded the .net web api ZIP.
Could you let me know specifically which file it is that you are using so I can try it locally, or what code you are using? Also, to confirm is it the server-side .NET
postCreate
or the client-sidepostCreate
that you are attempting to use?I've just tried the following on the server-side:
and it does appear to trigger correctly.
Allan
Hi Allan,
I am trying to use the client side event. I can reproduce easily by editing the simple.html file and adding this logging code just after the editor is created. Note: I have logging code for preCreate and postCreate (and every other event) but omitted these here for brevity.
The create event never gets fired or any created related event (pre, post, etc.). I have a need for the post create event but the others don't fire as well. And new records only show up on a refresh unless I add code in the submitComplete to force it. Note update and delete work fine.
Mike
Hi Mike,
It sounds like the server isn't returning the data for the new row when the create Ajax request is submitted. Can you show me the JSON that it is returning?
Thanks,
Allan
It isn't returning data from the ajax call (looking at response.data). When I do get the records initially, I see the data in the table and of course it's in the response object. But not on create.
I am using SQLite - don't know if that matters?
My C# web api code:
[Route("api/ShopifyAddresses")]
[HttpGet]
[HttpPost]
public IHttpActionResult ShopifyAddresses()
{
var request = HttpContext.Current.Request;
using (var db = new Database("sqlite", AppSettingsUtil.GetConnectionString("SQLITE")))
{
var response = new Editor(db, "ShopifyAddress", "ID")
.Model<DTShopifyAddress>()
.Field(new Field("ID"))
.Field(new Field("CustomerID"))
.Field(new Field("FirstName"))
.Field(new Field("LastName"))
.Field(new Field("Company"))
.Field(new Field("Address1"))
.Field(new Field("Address2"))
.Field(new Field("City"))
.Field(new Field("Province"))
.Field(new Field("Zip"))
.Field(new Field("CountryCode"))
.Process(request)
.Data();
return Json(response);
}
}
If it isn't returning the row that was created in the JSON, that explains why
create
isn't being triggered, nor is the row automatically showing. It sounds like the get id for the inserted row is failing. Could you show me your SQL schema for that table so I can try to reproduce it?Thanks,
Allan
Here you go:
"cid","name","type","notnull","dflt_value","pk"
"0","ID","INTEGER","0",NULL,"1"
"1","CustomerID","INTEGER","0",NULL,"0"
"2","FirstName","TEXT","0",NULL,"0"
"3","LastName","TEXT","0",NULL,"0"
"4","Company","TEXT","0",NULL,"0"
"5","Address1","TEXT","0",NULL,"0"
"6","Address2","TEXT","0",NULL,"0"
"7","City","TEXT","0",NULL,"0"
"8","Province","TEXT","0",NULL,"0"
"9","Zip","TEXT","0",NULL,"0"
"10","CountryCode","TEXT","0",NULL,"0"
Thanks - I'll try it out and get back to you. It might be after Christmas though I'm afraid.
Allan
Enjoy your Christmas Allan. And thanks for creating a great product.
Allan,
Do you have any update on this issue with SQLite?
Thanks,
Mike
Sorry - I've been bogged down with other things - it is on my list though! I'll post back here when done.
Allan
I had a problem like this where the record was created, but it wouldn't show up in the table until a page refresh and preCreate() and postCreate() were not firing. I was able to resolve this by using the full column name for the primary key field in the Editor setup versus the shortened name that was specified in the back-end.
Back-end:
Field::inst( 'units_id', 'id')
Front-end:
}, {
label: "Units ID:",
name: "units_id", // have to use the full name instead of just the shortened name, "id", as I had used for other fields
type: "hidden",
}, {