Uncaught Type Error: a is not a function

Uncaught Type Error: a is not a function

tomleongtomleong Posts: 13Questions: 5Answers: 0

Dear all,

I created a Editor on my MVC project and got the below running time error after update a record.
The record could be updated but the update panel did not disappear.

dataTables.editor.min.js:110 Uncaught TypeError: a is not a function
at f.edit (dataTables.editor.min.js:110)
at f._dataSource (dataTables.editor.min.js:81)
at f._submitSuccess (dataTables.editor.min.js:99)
at dataTables.editor.min.js:95
at Object.e.complete (dataTables.editor.min.js:76)
at fire (jquery-3.4.1.js:3291)
at Object.fireWith (jquery-3.4.1.js:3421)
at done (jquery-3.4.1.js:9548)
at XMLHttpRequest.<anonymous> (jquery-3.4.1.js:9785)

Server API :
[Route("api/SalesOrderLines/{orderNo}/orderNo")]
[HttpGet]
[HttpPost]

    public IHttpActionResult SalesOrderLines(string orderNo)
    {
        var request = HttpContext.Current.Request;
        var settings = Properties.Settings.Default;
        using (var tcdb = new DataTables.Database(settings.DbType, settings.DbConnection))
        {
            var response = new Editor(tcdb, "data.SalesOrderLine","id")
                .Model<SalesOrderLineEditViewModels>()
                //.Model<EditSalesOrderLineDto>()
                .Where("orderno" ,orderNo,"=")
                .Field(new Field("id"))
                .Field(new Field("partNo")
                .Validator(Validation.NotEmpty())
                )
                .Field(new Field("description")
                .Validator(Validation.NotEmpty())
                )
                .Field(new Field("orderQuantity")
                //.Validator(Validation.Numeric())
                )
                .Field(new Field("unitPrice")
                //.Validator(Validation.Numeric())
                )
                .Field(new Field("amount")
                //.Validator(Validation.Numeric())
                )
               .Field(new Field("requestDate")
                .Validator(Validation.DateFormat(
                       Format.DATE_ISO_8601,
                        new ValidationOpts { Message = "Please enter a date in the format yyyy-mm-dd" }
                    ))
                    .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_8601))
                    .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601))
                )
                /*.Field(new Field("requestDate")
                        .Validator(Validation.DateFormat("dd/MM/yy",
                         new ValidationOpts { Message = "Please enter a date in the format dd/MM/yy" }))
                        .GetFormatter(Format.DateSqlToFormat("dd/MM/yy"))
                        .SetFormatter(Format.DateFormatToSql("dd/MM/yy"))
                        )*/
                .Process(request)
                .Data();

            return Json(response);
        }
    }

View Model :

public class SalesOrderLineEditViewModels
{
[EditorTypeError("ID")]
public int id { get; set; }
[EditorTypeError("Order No")]
public string orderNo { get; set; }
[EditorTypeError("Order Type")]
public string orderType { get; set; }
[EditorTypeError("Line No")]
public int lineNo { get; set; }
[EditorTypeError("Part No")]
public string partNo { get; set; }
[EditorTypeError("Description")]
public string description { get; set; }
[EditorTypeError("Order Quantity")]
public int orderQuantity { get; set; }
[EditorTypeError("Open Quantity")]
public int openQuantity { get; set; }
[EditorTypeError("First Order Quantity")]
public int firstOrderQuantity { get; set; }
[EditorTypeError("Unit Price")]
public decimal unitPrice { get; set; }
[EditorTypeError("Amount must be decimal type.")]
public decimal amount { get; set; }
[EditorTypeError("Request date must be in format 'YYYY-MM-DD'.")]
public string requestDate { get; set; }
[EditorTypeError("Status")]
public string status { get; set; }
[EditorTypeError("Customer Part No")]
public string customerPartNo { get; set; }
[EditorTypeError("Sales Order Master ID")]
public int salesOrderMasterId { get; set; }

}

The test case link is as below.

http://live.datatables.net/bozuroze/1/edit?html,css,js,console

Thanks.

Tom

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    Hi Tom,

    What is the JSON response from the server as a result of the delete submit please?

    Allan

  • tomleongtomleong Posts: 13Questions: 5Answers: 0

    Dear Allan,

    The delete submit runs without problem. i captured the below from Chrome for your review. Please help. :)

    General : Request URL: http://localhost:49856/api/SalesOrderLines/14/orderNo
    Request Method: POST
    Status Code: 200 OK
    Remote Address: [::1]:49856
    Referrer Policy: no-referrer-when-downgrade
    Cache-Control: no-cache
    Content-Length: 189
    Content-Type: application/json; charset=utf-8
    Date: Tue, 23 Jul 2019 01:11:31 GMT
    Expires: -1
    Pragma: no-cache
    Server: Microsoft-IIS/10.0
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    X-SourceFiles: =?UTF-8?B?QzpcQ29kZVxUQ0hcVENIXGFwaVxTYWxlc09yZGVyTGluZXNcMTRcb3JkZXJObw==?=
    Accept: application/json, text/javascript, /; q=0.01
    Accept-Encoding: gzip, deflate, br
    Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7
    Connection: keep-alive
    Content-Length: 635
    Content-Type: application/x-www-form-urlencoded; charset=UTF-8
    Cookie: __RequestVerificationToken=BljuCPP_36dFbdKPO1fSlRDzX3gVBnLGOMeTgE1SIo0FuKZ9B3NTZBv7wFwfozTATlU2s0QGtqK-ossqye2TWcl_etnw3bvnpZB7cNfaesw1; .AspNet.ApplicationCookie=oyQ9bFxOVsCqh1EabHaRtN7zJtLAtgPfDCil_527yFk41gWPlZyg2VxUPU9NmcVoizJIqG4dqi_G7DQyDg5btKPIuyaRJa-9zAn8UCMONQ0DYN5fcMVzOQhg7XuT0SLyzgcAh1L4rBWrcA9Vqb96bUphu2An3BmKSSon_o1NofNqEZuBZnzHe-rfSVF4h5Z6UPsf9qqmp4Yt7MNcTPOaSxwetBSqxz9z2lPc8RUTy4WL89XwrDvDdLsEDFrTKpCINKdUkM20V4L0T77DaVAD08MFm94lHeLvcEcYtpShSjh4uA6YuVCKDI-9zEtOcwfA9qumBrq3djT1OJ5qhgKrTjUScj5va87Izq2fT6rsVgZCd2zV0RU4Lce5V2O3XHfmv77LpRqvttoOOnSPXSedg66JWKjrYIPp9Hmj8Y560jhwQpgFIgsGinfgxZJKDAQlQV4gv3qBqXqn7LjzittImy1WzTzDpj50hlGlLNXTNEJ8lFi_PTGxypNdxjg2beFqX1qJFz9hxZITqb2mjekSW3fjOJC8KAFk8XrTsa-fpzKuoZqkvMp7J25oyYFXqGZDWtrggY5-Tc9me037LyLQ5Q
    Host: localhost:49856
    Origin: http://localhost:49856
    Referer: http://localhost:49856/SalesOrders/Edit/14
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36
    X-Requested-With: XMLHttpRequest
    action: remove
    data[row_4][DT_RowId]: row_4
    data[row_4][id]: 4
    data[row_4][partNo]: Part No 12345
    data[row_4][description]: The first good description
    data[row_4][orderQuantity]: 121
    data[row_4][unitPrice]: 1.334
    data[row_4][amount]: 1300
    data[row_4][requestDate]: 2019-07-04
    data[row_4][orderNo]: 14
    data[row_4][orderType]: SD
    data[row_4][lineNo]: 1
    data[row_4][openQuantity]: 1000
    data[row_4][firstOrderQuantity]: 1000
    data[row_4][status]: 100
    data[row_4][customerPartNo]: CustPartNo133
    data[row_4][salesOrderMasterId]: 14
    
    
    ​Thanks.

    Tom

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    Allan asked for the JSON response. The above is the Ajax request.

    Kevin

  • tomleongtomleong Posts: 13Questions: 5Answers: 0

    Hi Kevin,

    Is it the following data?

    {"draw":null,"data":[],"recordsTotal":null,"recordsFiltered":null,"error":null,"fieldErrors":[],"id":null,"meta":{},"options":{},"files":{},"upload":{"id":null},"debug":null,"cancelled":[]}

    Thanks.

    Tom

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Hi @tomleong ,

    Just to be clear, is that the response that occurs after the delete? You can grab it from the browser's development tools (F12) and then the network tab.

    Cheers,

    Colin

  • tomleongtomleong Posts: 13Questions: 5Answers: 0

    Dear Colin,

    Yes, i copied the data after deletion.
    Thanks.

    Best regards,
    Tom

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    My apologies - I misunderstood your original question. I had thought it was a problem with deleting the data, but re-reading it now, I see that its a problem with editing the data. Is that correct? If so, could you show me the JSON return from an edit action where you see this issue?

    Could you also use the debugger and send me an upload trace for your table please?

    Thanks,
    Allan

  • tomleongtomleong Posts: 13Questions: 5Answers: 0

    Dear Allan,

    Yes, i got an error when i updated a line. The data can be updated on database but the update panel does not disappear.

    Please see the JSON return as below.

    {"draw":null,"data":[{"DT_RowId":"row_1","id":1,"partNo":"Part No 12345","description":"The first good description","orderQuantity":1211,"unitPrice":1.3340,"amount":1300112.0000,"requestDate":"2019-07-04","orderNo":"14","orderType":"SD","lineNo":1,"openQuantity":1000,"firstOrderQuantity":1000,"status":"100","customerPartNo":"CustPartNo133","salesOrderMasterId":14}],"recordsTotal":null,"recordsFiltered":null,"error":null,"fieldErrors":[],"id":null,"meta":{},"options":{},"files":{},"upload":{"id":null},"debug":null,"cancelled":[]}

    The debug file is also uploaded and the code is eriwif.
    Thanks.

    Tom

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    Hi Tom,

    That's the JSON in response to an edit action? That looks fairly sensible, so if there isn't a JS error happening and shown on your browser's console, I'll need a link to the page you are working on so I can debug it I'm afraid.

    Allan

  • Mark HeddaeusMark Heddaeus Posts: 1Questions: 0Answers: 0

    Hi Tom,

    Did you ever figure out the problem?

    I'm getting a similar error when doing an update.

    Thanks,
    Joe

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    @Mark Heddaeus The thread went quiet. If you're seeing the same problem, please could you follow the steps Allan suggested, including posting the JSON that's sent in response to the edit action. If nothing obvious, could you also link to your page, please,

    Colin

This discussion has been closed.