Editor ajax.data error - cannot set property of undefined - only after create?

Editor ajax.data error - cannot set property of undefined - only after create?

LmtarboxLmtarbox Posts: 9Questions: 3Answers: 0

I've attached a .txt with my editor and datatable code.

The edit functionality of my table/editor is working fine, but any time I try to create a new record, I'm hit with "error, cannot set property "commodity" of undefined" - referring to where I set d.commodity in the ajax.data portion of my datatable.

I've inspected the data going to and from the server, it all looks fine. Any idea where the problem is?

Answers

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147

    If you are referring to this section of code:

           "ajax": {
                "url": "/ActiveContracts/LoadData",
                "type": "POST",
                "data": function (d) {
                    d.commodity = $('#commodity').val();
    

    Nothing obvious stands out as an issue. The code looks like the function example in the ajax.data docs.

    Can you post a link to your page or a test case replicating the issue so we can take a look?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • LmtarboxLmtarbox Posts: 9Questions: 3Answers: 0

    That's what I'm referring to - unfortunately, having trouble building out my code in a test case. I'll keep trying, but can you think of any reason why ajax.data wouldn't work when being called after a create? I tried renaming the d to a different letter in case there was just a conflicting variable somewhere in my code, but no luck.

  • LmtarboxLmtarbox Posts: 9Questions: 3Answers: 0

    What is called after Editor's create function runs? Is it just a .reload on the datatable, or is it a .draw?

  • colincolin Posts: 8,995Questions: 0Answers: 1,501

    It's a draw. As Kevin said, nothing looks obviously wrong, are you able to link your page so we can see?

    Colin

  • LmtarboxLmtarbox Posts: 9Questions: 3Answers: 0

    Hi Colin,

    I'm having issues getting a test case to work. I've been doing some debugging on my end - I've realized that the issue is connected to the fact that I have a second Editor attached to the same table. I used the same template and ajax as the first editor, just changed the name to editor2, and call that editor with the Future Edit button. That's when the issues crop up when trying to Create with either editor.

    I'll try making another test case. I was going to attach another .txt but I guess you can only do that in the main post?

    Thanks,
    Logan

  • colincolin Posts: 8,995Questions: 0Answers: 1,501

    With two Editor instances, we're really going to need to see it as that's fairly non-standard. If you're struggling with the test case, you could try using this one here as a template perhaps.

    Colin

  • LmtarboxLmtarbox Posts: 9Questions: 3Answers: 0

    I don't know if I can give a real test case because I'm using server-side.

    I've gotten rid of the multiple editors, I have everything down to the one editor and I think I've narrowed down the problem - I only get an error if I have an event with an ajax call inside of it. For instance, I was trying with my Future Edit button to use an ajax call on .postSubmit to update some other records through a server-side script, but I think sending data to that ajax call messes with the data being sent to the datatable ajax call.

    I tried a different approach after that - calling the custom ajax after table.on(draw). Same issue, I then get an error in the datatable's ajax call when it tries to draw again. It's almost like my other ajax calls are breaking the ajax call on the table's draw.

  • allanallan Posts: 51,923Questions: 1Answers: 7,873 Site admin

    Can you use the debugger to give me a trace please (or the page showing the error) - click the Upload button and then let me know what the debug code is.

    There doesn't appear to be anything wrong with the ajax.data function in your original txt file , but it sounds like there are some other things going on as well, so being able to see a trace would be useful.

    It's almost like my other ajax calls are breaking the ajax call on the table's draw.

    I only see the DataTables ajax and Editor ajax setup in the text file. Are there others on your page as well. I might be able to diagnose it without a link to the page, but I'd need to be able to see the full code.

    Thanks,
    Allan

Sign In or Register to comment.